Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/powpeg validation protocol integration #374

Open
wants to merge 112 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
4880878
refactor(fed): federation watcher tests
apancorb Sep 30, 2024
2ad52bd
feat(federate): change access modifier for federation watcher listerner
apancorb Oct 2, 2024
2f64531
fix(btcreleaseclient): remove signature cache dependency from BridgeE…
apancorb Oct 23, 2024
44d4e58
feat(federate): implement getProposedFederationAddress in federation …
apancorb Oct 23, 2024
0d1fc76
feat(bitcoin): add bitcoin test util methods
apancorb Oct 24, 2024
0141296
refactor(watcher): refactor federation watcher to its own package
apancorb Oct 21, 2024
feb04fc
refactor(watcher): simplify FederationWatcherListener interface and a…
apancorb Oct 22, 2024
970bd25
refactor(watcher): organize and remove some comments for FederationWa…
apancorb Oct 23, 2024
959d509
feat(btcreleaseclient): federator should be part of the federation wh…
apancorb Oct 24, 2024
9b8c820
feat(federate): throw an exception if federator is not a member of th…
apancorb Oct 24, 2024
f42ddb4
feat(watcher): change stop and starting logic when active and retirin…
apancorb Oct 24, 2024
fd35e17
refactor(watcher): rename interface variables to be more explicit and…
apancorb Oct 25, 2024
ec8b42b
fix(federate): solve unit tests since was using a member not part of …
apancorb Oct 25, 2024
225a1ff
refactor(watcher): change updateActiveFederation to use the original …
apancorb Oct 29, 2024
9aef1c1
refactor(watcher): small code structure change and better logging
apancorb Oct 29, 2024
a5adc16
feat(watcher): make the active federation be required to be non-null
apancorb Oct 29, 2024
7243352
refactor(btcreleaseclient): make better log statements for start and …
apancorb Oct 30, 2024
7c1e1c2
fix(btcreleaseclient): if the member running the node is not part of …
apancorb Oct 30, 2024
0daf69c
feat(btcreleaseclient): add unit test for federation member is not pa…
apancorb Oct 30, 2024
8b39470
feat(watcher): add unit tests for FederationWatcherListenerImpl
apancorb Oct 30, 2024
21114f8
feat(config): add description for isPegoutEnabled parameter
apancorb Nov 7, 2024
ca64896
refactor(federate): remove unused method getLiveFederations
apancorb Nov 7, 2024
1724576
refactor(federate): remove unused unit tests for getLiveFederations m…
apancorb Nov 7, 2024
0931b4c
refactor(btcreleaseclient): enhance javadoc for class
apancorb Oct 28, 2024
42ba67f
refactor(btcreleaseclient): small refactor to include proper spaces a…
apancorb Oct 28, 2024
ffc0e5e
feat(federate): add bridge call to retrieve svp spend tx waiting for …
apancorb Oct 28, 2024
1b3008c
refactor(federate): remove unnecessary blank lines in FederateSupport…
apancorb Oct 28, 2024
d9c6b63
feat(btcreleaseclient): add call to getStateForProposedFederator when…
apancorb Oct 28, 2024
7f5453c
refactor(btcreleaseclient): small change to code structure for rsk tx…
apancorb Oct 29, 2024
c45e3f4
feat(btcreleaseclient): add unit tests for svp tx waiting for signatu…
apancorb Oct 29, 2024
2ffa484
refactor(btcreleaseclient): reword svp spend comment
apancorb Nov 1, 2024
d99362b
refactor(btcreleaseclient): propper code formatting
apancorb Nov 1, 2024
6c78faa
feat(btcreleaseclient): add receipt store logic to find the block has…
apancorb Nov 1, 2024
78caae8
feat(federate): add receipt store dependency to BtcReleaseClient class
apancorb Nov 1, 2024
9e3098d
feat(btcreleaseclient): add confirmation diff logic using the receipt…
apancorb Nov 1, 2024
8c3c537
fix(btcreleaseclient): avoid shadowing receipt store instance variable
apancorb Nov 1, 2024
ad7f04a
feat(btcreleaseclient): include is ready to sign method only for the …
apancorb Nov 4, 2024
cb3afbb
refactor(btcreleaseclient): update log statement
apancorb Nov 4, 2024
ce1c42f
feat(btcreleaseclient): use mainnet params for unit tests
apancorb Nov 5, 2024
ad74ca0
feat(btcreleaseclient): add better naming for unit tests vars
apancorb Nov 5, 2024
2c84ecb
feat(btcreleaseclient): add both svp spend tx and pegout unit test an…
apancorb Nov 5, 2024
8f1116c
refactor(btcreleaseclient): reuse fed key for unit test
apancorb Nov 5, 2024
b2c6091
feat(btcreleaseclient) add unit test for when pegouts and svp spend t…
apancorb Nov 5, 2024
8be36eb
feat(btcreleaseclient): update all fed ekys for unit tests
apancorb Nov 5, 2024
51937cc
feat(btcreleaseclient): add warning log in case isPegoutEnabled is di…
apancorb Nov 8, 2024
e7999da
feat(federate): add unit tests for getStateForProposedFederator
apancorb Nov 8, 2024
b5e3fc6
feat(btcreleaseclient): use ReleaseCreationInformationGetter to retri…
apancorb Nov 8, 2024
fb27153
feat(federate): add getProposedFederationSize to FederatorSupport
apancorb Oct 25, 2024
6fec3f0
feat(federate): add getProposedFederatorPublicKeyOfType to FederatorS…
apancorb Oct 25, 2024
5c26e35
feat(federate): add getProposedFederationCreationTime to FederatorSup…
apancorb Oct 25, 2024
4311475
feat(federate): add getProposedFederationCreationBlockNumber to Feder…
apancorb Oct 25, 2024
6792317
feat(federate): add getProposedFederation to FederationProvider inter…
apancorb Oct 25, 2024
2555f76
feat(federate): add implementation of getProposedFederation to Federa…
apancorb Oct 25, 2024
b54b217
refactor(federate): use FEDERATION_NON_EXISTENT enum code in conditio…
apancorb Oct 25, 2024
d1f52c8
feat(federate): add unit tests for getProposedFederationSize
apancorb Oct 25, 2024
340e680
feat(federate): add unit tests for getProposedFederatorPublicKeyOfType
apancorb Oct 25, 2024
98430bc
feat(federate): add unit tests for getProposedFederationCreationTime
apancorb Oct 25, 2024
08b0e4d
feat(federate): add unit tests for getProposedFederationCreationBlock…
apancorb Oct 25, 2024
c2a6872
feat(federate): add unit tests for getProposedFederation
apancorb Oct 25, 2024
3728215
fix(federate): use proper activation rule for svp
apancorb Oct 25, 2024
b17182c
refactor(federate): improve javadocs for FederationProvider interface
apancorb Oct 30, 2024
91d03ff
refactor(federate): use isEmpty when checking if retiring federation …
apancorb Oct 30, 2024
7667e17
feat(federate): throw exception if after proving that the proposed fe…
apancorb Oct 30, 2024
2b30329
refactor(federate): method call consistent with all the other propose…
apancorb Oct 30, 2024
cc386be
feat(federate): after rskip419 the only possible type of federation i…
apancorb Oct 30, 2024
3878f90
feat(federate): remove unit tests for proposed federation that are un…
apancorb Oct 30, 2024
33f81ba
fix(federate): update var name to not shadow global federator support…
apancorb Oct 30, 2024
356cfb0
refactor(federate): replace lambda with method reference 'IllegalStat…
apancorb Oct 30, 2024
34a2fb9
refactor(federate): improve sonar complaints of FederateSupport
apancorb Oct 30, 2024
5b27cbb
refactor(federate): make FederationProvider javadoc more concise
apancorb Oct 31, 2024
e7b2c6c
feat(federate): remove checking the proposed federation addr to valid…
apancorb Oct 31, 2024
3bdb4ac
feat(federate): remove unit tests verifying if proposed fed addr is b…
apancorb Oct 31, 2024
75869be
feat(federate): add try-catch block in case proposed federation is un…
apancorb Oct 31, 2024
36c1a85
feat(federate): add unit test when proposed federation cannot be buil…
apancorb Oct 31, 2024
69de28c
refactor(federate): rename unit tests
apancorb Nov 1, 2024
1e8fcaa
refactor(federate): use ECKey class to build pub key in unit tests
apancorb Nov 1, 2024
17f83dc
feat(federate): change catch exception class to catch all possible ex…
apancorb Nov 4, 2024
33f5b65
refactor(federate): remove checking if RSKIP419 is activated for prop…
apancorb Nov 4, 2024
718fb0c
feat(federate): remove RSKIP419 reference for unit tests
apancorb Nov 4, 2024
f55742a
feat(federate): remove unit tests related with proposed fed and rskip419
apancorb Nov 5, 2024
f399fd8
refactor(federate): remove Optional flat map to get the addr of the p…
apancorb Nov 5, 2024
45a1412
feat(federate): remove unnecessary use of mocking activations in unit…
apancorb Nov 6, 2024
396f551
refactor(federate): removed checking if retiring fed addr is present …
apancorb Nov 8, 2024
cd8b06f
feat(federate): Change getProposedFederationCreationTime to return In…
apancorb Nov 8, 2024
de828fb
feat(federate): wrap logic for building the retiring fed in try-catch
apancorb Nov 12, 2024
41a0d1a
refactor(federate): enhance javadoc for FederationProviderFromFederat…
apancorb Nov 12, 2024
a02d3ed
feat(federate): add unit test when getting addr for retiring fed does…
apancorb Nov 12, 2024
f41358b
feat(federate): allow exception to propagate in the listener if unabl…
apancorb Nov 13, 2024
aa42066
feat(watcher): add onProposedFederation method to interface
apancorb Nov 4, 2024
e466c1b
feat(watcher): intial implementation of onProposedFederationChange
apancorb Nov 4, 2024
24a2638
feat(watcher): enhance with try-catch and logging onProposedFederatio…
apancorb Nov 6, 2024
d031b75
feat(watcher): use javadoc annotation for comment in onProposedFedera…
apancorb Nov 6, 2024
226033e
feat(watcher): add unit tests for onProposedFederationChange
apancorb Nov 6, 2024
5f4dea3
feat(watcher): implement onProposedFederationChange for anoymous clas…
apancorb Nov 6, 2024
52e7481
feat(watcher): add logic for change in proposed fed in FederationWatc…
apancorb Nov 12, 2024
73b14bd
refactor(watcher): use mock of federation watcher listener instead of…
apancorb Nov 12, 2024
4d27db9
feat(watcher): accomdate existing unit tests for proposed fed logic
apancorb Nov 12, 2024
6f4bfb1
feat(watcher): call updateProposedFederation before updateActiveFeder…
apancorb Nov 12, 2024
232bbf7
feat(watcher): add unit test for proposed federation in FederationWat…
apancorb Nov 12, 2024
85dc6fc
refactor(wathcer): log statement for onProposedFederationChange
apancorb Nov 12, 2024
3a292fa
refactor(watcher): test naming and log statements
apancorb Nov 12, 2024
3f5f5b9
fix(federate): add RSKIP419 check for proposed federation methods
apancorb Nov 19, 2024
72a5e05
Adapt to time unit bridge method change
julia-zack Dec 5, 2024
35649ec
Add tests pre rskip 419
julia-zack Dec 6, 2024
b19f6ee
fix(btcreleaseclient): place call to get svp spend tx wfs behind acti…
apancorb Nov 21, 2024
42745d4
fix(watcher): add correct log prefix
apancorb Nov 22, 2024
2c7efb8
feat(bitcoin): add logic to detect when processing a svp spend tx
apancorb Dec 6, 2024
cfbce55
refactor(federate): add proper spacing between code segments
apancorb Dec 11, 2024
ad7dbb1
refactor(federate): move code segments in BtcToRskClient
apancorb Dec 11, 2024
13d4130
feat(bitcoin): remove svp spend tx handling in BitcoinWrapperImpl
apancorb Dec 11, 2024
e243551
feat(watcher): add BitcoinWrapper to onProposedFederationChange so it…
apancorb Dec 11, 2024
7231fa9
feat(watcher): update unit tests to accomdate BitcoinWrapper listener…
apancorb Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions src/main/java/co/rsk/federate/BtcToRskClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,26 @@ public synchronized void setup(
public void start(Federation federation) {
logger.info("[start] Starting for Federation {}", federation.getAddress());
this.federation = federation;

FederationMember federator = federatorSupport.getFederationMember();
boolean isMember = federation.isMember(federator);

if (!isMember) {
logger.info("[start] member {} is no part of the federation {} ",
String message = String.format(
"Member %s is no part of the federation %s",
federator.getBtcPublicKey(),
federation.getAddress());
return;
logger.error("[start] {}", message);
throw new IllegalStateException(message);
}

logger.info("[start] {} is member of the federation {}",
federator.getBtcPublicKey(), federation.getAddress());
logger.info("[start] Watching federation {} since I belong to it",
federation.getAddress());
bitcoinWrapper.addFederationListener(federation, this);

Optional<Integer> federatorIndex = federation.getBtcPublicKeyIndex(
federatorSupport.getFederationMember().getBtcPublicKey()
);
federatorSupport.getFederationMember().getBtcPublicKey());
if (!federatorIndex.isPresent()) {
String message = String.format(
"Federator %s is a member of the federation %s but could not find the btcPublicKeyIndex",
Expand All @@ -138,34 +140,33 @@ public void start(Federation federation) {
logger.error("[start] {}", message);
throw new IllegalStateException(message);
}
TurnScheduler scheduler = new TurnScheduler(
bridgeConstants.getUpdateBridgeExecutionPeriod(),
federation.getSize()
);
long now = Clock.systemUTC().instant().toEpochMilli();

if (isUpdateBridgeTimerEnabled) {
updateBridgeTimer = Executors.newSingleThreadScheduledExecutor();
long now = Clock.systemUTC().instant().toEpochMilli();
TurnScheduler scheduler = new TurnScheduler(
bridgeConstants.getUpdateBridgeExecutionPeriod(),
federation.getSize());

this.updateBridgeTimer = Executors.newSingleThreadScheduledExecutor();

updateBridgeTimer.scheduleAtFixedRate(
this::updateBridge,
scheduler.getDelay(now, federatorIndex.get()),
scheduler.getInterval(),
TimeUnit.MILLISECONDS
);
}
else {
TimeUnit.MILLISECONDS);
} else {
logger.info("[start] updateBridgeTimer is disabled");
}
}

public void stop() {
logger.info("Stopping");

federation = null;
this.federation = null;

if (updateBridgeTimer != null) {
updateBridgeTimer.shutdown();
updateBridgeTimer = null;
this.updateBridgeTimer = null;
}
}

Expand All @@ -177,13 +178,15 @@ public void updateBridge() {
if (federation == null) {
logger.warn("[updateBridge] updateBridge skipped because no Federation is associated to this BtcToRskClient");
}

if (nodeBlockProcessor.hasBetterBlockToSync()) {
logger.warn("[updateBridge] updateBridge skipped because the node is syncing blocks");
return;
}

logger.debug("[updateBridge] Updating bridge");

if(shouldUpdateBridgeBtcBlockchain) {
if (shouldUpdateBridgeBtcBlockchain) {
// Call receiveHeaders
try {
int numberOfBlocksSent = updateBridgeBtcBlockchain();
Expand All @@ -194,7 +197,7 @@ public void updateBridge() {
}
}

if(shouldUpdateBridgeBtcCoinbaseTransactions) {
if (shouldUpdateBridgeBtcCoinbaseTransactions) {
// Call registerBtcCoinbaseTransaction
try {
logger.debug("[updateBridge] Updating transactions and sending update");
Expand All @@ -205,7 +208,7 @@ public void updateBridge() {
}
}

if(shouldUpdateBridgeBtcTransactions) {
if (shouldUpdateBridgeBtcTransactions) {
// Call registerBtcTransaction
try {
logger.debug("[updateBridge] Updating transactions and sending update");
Expand All @@ -216,7 +219,7 @@ public void updateBridge() {
}
}

if(shouldUpdateCollections) {
if (shouldUpdateCollections) {
// Call updateCollections
try {
logger.debug("[updateBridge] Sending updateCollections");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/co/rsk/federate/FedNodeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import co.rsk.federate.signing.hsm.advanceblockchain.HSMBookKeepingClientProvider;
import co.rsk.federate.signing.hsm.client.HSMClientProtocolFactory;
import co.rsk.federate.solidity.DummySolidityCompiler;
import co.rsk.federate.watcher.FederationWatcher;
import java.util.concurrent.TimeUnit;
import org.ethereum.rpc.Web3;
import org.ethereum.solidity.compiler.SolidityCompiler;
Expand Down
50 changes: 11 additions & 39 deletions src/main/java/co/rsk/federate/FedNodeRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
import co.rsk.federate.signing.hsm.message.SignerMessageBuilderFactory;
import co.rsk.federate.signing.hsm.requirements.AncestorBlockUpdater;
import co.rsk.federate.signing.hsm.requirements.ReleaseRequirementsEnforcer;
import co.rsk.peg.federation.Federation;
import co.rsk.federate.watcher.FederationWatcher;
import co.rsk.federate.watcher.FederationWatcherListener;
import co.rsk.federate.watcher.FederationWatcherListenerImpl;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.btcLockSender.BtcLockSenderProvider;
import co.rsk.peg.pegininstructions.PeginInstructionsProvider;
Expand All @@ -65,7 +67,6 @@
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -342,27 +343,14 @@ private void startFederate() throws Exception {
config.getBtcReleaseClientInitializationMaxDepth()
)
);
federationWatcher.setup(federationProvider);

federationWatcher.addListener(new FederationWatcher.Listener() {
@Override
public void onActiveFederationChange(Optional<Federation> oldFederation, Federation newFederation) {
String oldFederationAddress = oldFederation.map(f -> f.getAddress().toString()).orElse("NONE");
String newFederationAddress = newFederation.getAddress().toString();
logger.debug(String.format("[onActiveFederationChange] Active federation change: from %s to %s", oldFederationAddress, newFederationAddress));
triggerClientChange(btcToRskClientActive, Optional.of(newFederation));
}

@Override
public void onRetiringFederationChange(Optional<Federation> oldFederation, Optional<Federation> newFederation) {
String oldFederationAddress = oldFederation.map(f -> f.getAddress().toString()).orElse("NONE");
String newFederationAddress = newFederation.map(f -> f.getAddress().toString()).orElse("NONE");
logger.debug(String.format("[onRetiringFederationChange] Retiring federation change: from %s to %s", oldFederationAddress, newFederationAddress));
triggerClientChange(btcToRskClientRetiring, newFederation);
}
});
// Trigger the first events
federationWatcher.updateState();

FederationWatcherListener federationWatcherListener = new FederationWatcherListenerImpl(
btcToRskClientActive,
btcToRskClientRetiring,
btcReleaseClient,
bitcoinWrapper);

federationWatcher.start(federationProvider, federationWatcherListener);
}
}

Expand All @@ -384,22 +372,6 @@ private void shutdown() {
System.exit(-1);
}

// TODO: This this method (and this whole class)
private void triggerClientChange(BtcToRskClient client, Optional<Federation> federation) {
client.stop();
federation.ifPresent(btcReleaseClient::stop);
// Only start if this federator is part of the new federation
if (federation.isPresent() && federation.get().isMember(this.member)) {
String federationAddress = federation.get().getAddress().toString();
logger.debug("[triggerClientChange] Starting lock and release clients since I belong to federation {}", federationAddress);
logger.info("[triggerClientChange] Joined to {} federation", federationAddress);
client.start(federation.get());
btcReleaseClient.start(federation.get());
} else {
logger.warn("[triggerClientChange] This federator node is not part of the new federation. Check your configuration for signers BTC, RSK and MST keys");
}
}

@Override
public void stop() {
logger.info("[stop] Shutting down Federation node");
Expand Down
55 changes: 40 additions & 15 deletions src/main/java/co/rsk/federate/FederationProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,59 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package co.rsk.federate;

import co.rsk.bitcoinj.core.Address;
import co.rsk.peg.federation.Federation;

import java.util.List;
import java.util.Optional;

/**
* Implementors of this interface must be able to provide
* federation instances.
*
* @author Ariel Mendelzon
* Provides access to various federation instances, including the active, retiring, and proposed federations.
* Implementations of this interface must define how to retrieve the federations and their respective addresses.
* These methods allow clients to manage and monitor federations in different lifecycle stages within the bridge.
*/
public interface FederationProvider {
// The currently "active" federation

/**
* Retrieves the currently active federation.
*
* @return the active {@link Federation} instance
*/
Federation getActiveFederation();
// The currently "active" federation's address

/**
* Retrieves the address of the currently active federation.
*
* @return the {@link Address} of the active federation
*/
Address getActiveFederationAddress();

// The currently "retiring" federation
/**
* Retrieves the currently retiring federation, if one exists. This federation is in transition
* and will soon be replaced by a new active federation.
*
* @return an {@link Optional} containing the retiring {@link Federation}, or {@link Optional#empty()} if none exists
*/
Optional<Federation> getRetiringFederation();
// The currently "retiring" federation's address

/**
* Retrieves the address of the currently retiring federation, if one exists.
*
* @return an {@link Optional} containing the {@link Address} of the retiring federation, or {@link Optional#empty()} if none exists
*/
Optional<Address> getRetiringFederationAddress();

// The federations that are "live", that is, are still
// operational. This should be the active federation
// plus the retiring federation, if one exists
List<Federation> getLiveFederations();
/**
* Retrieves the currently proposed federation, if one exists. This federation is awaiting validation.
*
* @return an {@link Optional} containing the proposed {@link Federation}, or {@link Optional#empty()} if none exists
*/
Optional<Federation> getProposedFederation();

/**
* Retrieves the address of the currently proposed federation, if one exists.
*
* @return an {@link Optional} containing the {@link Address} of the proposed federation, or {@link Optional#empty()} if none exists
*/
Optional<Address> getProposedFederationAddress();
}
Loading
Loading