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

Pegin tests integration #2895

Draft
wants to merge 201 commits into
base: feature/powpeg_validation_protocol-integration
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
201 commits
Select commit Hold shift + click to select a range
2b18b57
Add logic to extractWitnessCommitmentHash in the Bridge
marcos-iov Dec 11, 2024
200f8bf
Add rskip419 config to lovell
julia-zack Jul 18, 2024
71a3d23
Add validation period duration to federation constants
julia-zack Jul 18, 2024
75acc44
Add proposedFederation and validationFundTxHashUnsigned
julia-zack Jul 18, 2024
051b172
Add keys to storage index
julia-zack Jul 18, 2024
6b4cacb
Add set and save methods for the proposed federation
julia-zack Jul 18, 2024
a5d4a1d
Save proposed federation with its own format version
julia-zack Jul 22, 2024
8b01467
Add tests for saveProposedFederation method
julia-zack Jul 31, 2024
afa1c78
Add format version assertion to tests
julia-zack Jul 31, 2024
8579f8f
Add getProposedFederation method
julia-zack Jul 31, 2024
02d0164
Adds setFundTransactionUnsignedHash and saveFundTransactionUnsignedHa…
jeremy-then Jul 29, 2024
64e9b92
Add set and save methods for the proposed federation
julia-zack Jul 18, 2024
bebd958
Save null version when proposed federation is null
julia-zack Jul 23, 2024
50141ce
Add getProposedFederation method
julia-zack Jul 31, 2024
11c3d74
Throw exception when there is no storage version for non-null propose…
julia-zack Aug 1, 2024
dc67300
Adds setFundTransactionUnsignedHash and saveFundTransactionUnsignedHa…
jeremy-then Jul 29, 2024
ba161a8
Adds getSvpFundTransactionUnsignedHash and tests
jeremy-then Aug 5, 2024
eb568a5
Split commit federation. Disable failing test
julia-zack Jul 31, 2024
e85d638
Add tests to existing nested class
julia-zack Aug 8, 2024
98f0822
Comment broken test that be addressed later
julia-zack Aug 8, 2024
e84b02e
Move svp fund tx hash unsigned entry from federation storage index ke…
julia-zack Aug 13, 2024
c2dc399
Remove svp fund tx logic from federation storage provider, and add it…
julia-zack Aug 13, 2024
2b5b52c
Define spendable value directly in BridgeConstants
julia-zack Aug 15, 2024
7836c0f
Add getProposedFederation method in FederationSupport
julia-zack Aug 15, 2024
d265a5c
Add proposed federation dummy flyover prefix to bridge constants
julia-zack Aug 19, 2024
a449af0
Create new settleReleaseRequest method to perform common actions when…
julia-zack Aug 19, 2024
3766a35
Add svp fund tx hash signed storage index key
julia-zack Aug 19, 2024
e277baa
Add set and save methods
julia-zack Aug 19, 2024
3af0fd9
Add getSvpFundTxHashSigned method
julia-zack Aug 19, 2024
30447cf
Move vote federation change nested test class to its own file
julia-zack Aug 19, 2024
c3cfc08
Add tests
julia-zack Aug 15, 2024
9737d4e
Add flyover output to fund tx. Refactor
julia-zack Aug 16, 2024
37b28a7
Add reused method to PegUtils
julia-zack Aug 16, 2024
e1bf35c
Take nested SvpTests out of nested locking cap tests
julia-zack Aug 16, 2024
f46c34a
Use flyover rs builder. Remove method from PegUtils
julia-zack Aug 19, 2024
98b0230
Create output to federation with flyover prefix with address instead …
julia-zack Aug 21, 2024
c07eac7
Add test for insufficient money exception test.
julia-zack Aug 21, 2024
52bb6a4
Call new method for FlyoverRedeemScriptBuilder
marcos-iov Sep 17, 2024
058ee36
feat(peg): add svp spend tx hash unsigned storage entry
apancorb Aug 28, 2024
1c9e3c4
feat(peg): add set and save storage methods for svp spend unsigned tx…
apancorb Aug 29, 2024
c3f6cc6
feat(peg): add getter for svp spend tx hash
apancorb Aug 30, 2024
8c2c3c8
feat(peg): add serialize and deserialize map logic with tests
apancorb Sep 2, 2024
47a7566
feat(peg): add svp spend tx waiting for signatures data structure
apancorb Sep 2, 2024
60e8fe0
refactor(peg): change serialization naming for rsk txs waiting for si…
apancorb Sep 3, 2024
4127148
Create method to remove signatures from script sig
julia-zack Sep 5, 2024
010258e
Add methods to create a real valid chain with stored blocks to avoid …
julia-zack Sep 10, 2024
5d196f6
Add method to check if svp is ongoing
julia-zack Sep 5, 2024
4475e7f
feat(peg): add svp spend tx waiting for signatures storage key
apancorb Sep 11, 2024
03cfae6
feat(peg): add logic to save svp spend tx waiting for signatures with…
apancorb Sep 11, 2024
7c1b9bf
feat(peg): allow null default entry for resetting svp spend tx waitin…
apancorb Sep 12, 2024
90d8de3
feat(peg): if empty svp spend tx waiting for signatures attempted to …
apancorb Sep 13, 2024
cf36caf
fix(peg): fix error message in svp spend tx waiting for signatures ex…
apancorb Sep 13, 2024
274b8f0
feat(peg): add null key and value for svp spend tx waiting for signat…
apancorb Sep 13, 2024
0a656e9
feat(peg): add setter for svp spend tx waiting for signatures field i…
apancorb Sep 16, 2024
3ef6f50
Move svpSpendTxWaitingForSignatures validation to set method
marcos-iov Sep 16, 2024
1dda566
feat(peg): add get svp spend tx waiting for signatures logic and unit…
apancorb Sep 13, 2024
36651a6
Move flyover methods from BridgeSupport to PegUtils
julia-zack Sep 17, 2024
e522b02
Create new methods to handle btc tx deserialization without inputs to…
julia-zack Sep 17, 2024
0d7e5b1
When signed, save the svp fund tx instead of its hash
julia-zack Sep 16, 2024
c6accad
refactor(peg): state for federator refactor including tests
apancorb Sep 19, 2024
89fa92d
feat(peg): add state for proposed federator
apancorb Sep 19, 2024
ee02c48
feat(peg): add deserialization logic for federator states
apancorb Sep 20, 2024
ffa1bb3
feat(peg): simplify state for federator tests and add state for feder…
apancorb Sep 20, 2024
18e289d
Add tests for registering the svp fund transaction through registerBt…
julia-zack Sep 12, 2024
839563f
Add test for svp transaction without output change
julia-zack Sep 16, 2024
a9abd89
Adapt to have the svp fund tx signed instead of the hash
julia-zack Sep 16, 2024
530c845
Consider segwit transactions too when checking for svp fund transacti…
julia-zack Sep 23, 2024
f7386d9
Simplify transaction hash comparison for svp fund transaction
julia-zack Sep 23, 2024
9eb2c34
Use Optional API to make code more concise and functional. Wrap long …
julia-zack Sep 24, 2024
fe25c53
Move test for svp fund tx registration to BridgeSupportRegisterBtcTra…
julia-zack Sep 25, 2024
c013c93
Move svp fund transaction tests to new FederationChangeTest class
julia-zack Sep 25, 2024
9f6c7aa
Rename test file
julia-zack Sep 25, 2024
b70df2b
feat(peg): add getStateForSvpClient Bridge method
apancorb Sep 23, 2024
41e0080
fix(peg): fix issue with serializing RLP list twice
apancorb Sep 23, 2024
7ea6430
chore(peg): todo comment for fixed cost value
apancorb Sep 24, 2024
40edf54
feat(peg): add type safety for bridge method getStateForSvpClient
apancorb Sep 24, 2024
4ed5966
feat(peg): rollback to include current serialization logic for state …
apancorb Sep 26, 2024
a37f5b3
Move searchForOutput method to BitcoinUtils to reuse it
julia-zack Sep 25, 2024
3141b55
Create and process svp spend transaction
julia-zack Sep 25, 2024
c7eaac2
Add tests to spend transaction process. Refactor some methods to avoi…
julia-zack Sep 26, 2024
989de39
Create new method in BitcoinUtils to remove duplicated code from Brid…
julia-zack Sep 26, 2024
d1d9b59
Add hsm-needed pegout logging for svp spend tx. Remove duplicated code
julia-zack Sep 26, 2024
2676ebd
Add assertions to new logged events. Reorder methods to be more organ…
julia-zack Sep 26, 2024
62fa1ba
Refactor method to avoid throwing exception unnecessary. Rename metho…
julia-zack Sep 26, 2024
6fd5d73
Rename method that calculates amount to be sent in svp spend tx. Repl…
julia-zack Sep 26, 2024
6e295cc
Add missing empty p2sh input script to svp spend transaction
julia-zack Sep 30, 2024
62810e3
Add tests to check if svp spend tx inputs have expected script sig
julia-zack Oct 1, 2024
b82cf07
Refactor BridgeEventLoggerImpl
julia-zack Sep 27, 2024
6d7f3b4
Refactor BridgeEventLoggerImpl to not receive SignatureCache object
marcos-iov Sep 27, 2024
2216e0c
Remove unnecessary (since we are unit-testing) arguments from asserti…
julia-zack Sep 27, 2024
5ad5151
feat(federation): add getProposedFederationAddress method to Federati…
apancorb Oct 2, 2024
a15fce5
feat(federation): add getProposedFederationSize to Federation Support
apancorb Oct 2, 2024
f7e0c70
Create new commitFederationFailed Bridge event
julia-zack Sep 27, 2024
c81e674
Add test for logCommitFederationFailure from deprecated logger
julia-zack Oct 1, 2024
5b43df2
Move rsk block creation method to RskTestUtils
julia-zack Oct 3, 2024
238eaef
Remove unnecessary suffix from variable name
julia-zack Oct 3, 2024
720cc9c
Create default implementation of createRskBlock util method
marcos-iov Oct 3, 2024
dac428a
feat(federation): add getProposedFederationCreationTime in Federation…
apancorb Oct 2, 2024
9fd5e7f
feat(federation): add getProposedFederationCreationBlockNumber method…
apancorb Oct 2, 2024
cdac7b5
feat(peg): add getProposedFederationAddress Bridge method
apancorb Oct 3, 2024
1f0c7fc
feat(peg): Update Bridge
apancorb Oct 4, 2024
028d7ea
feat(federation): add getProposedFederatorPublicKeyOfType method in F…
apancorb Oct 2, 2024
0a3353e
refactor(federation): tidy up federation builder
apancorb Oct 3, 2024
b1a74ed
feat(federation): add more unit tests per key type when empty federation
apancorb Oct 4, 2024
5b7c4e9
feat(federation): add javadoc for getProposedFederationCreationTime i…
apancorb Oct 7, 2024
ab241ef
feat(peg): add getProposedFederationCreationTime Bridge method
apancorb Oct 7, 2024
d141056
feat(federation): add javadoc for getProposedFederationCreationBlockN…
apancorb Oct 7, 2024
35f2b2c
feat(peg): add getProposedFederationCreationBlockNumber Bridge Method
apancorb Oct 7, 2024
8cf07c6
feat(federation): add javadoc for getProposedFederationSize in Federa…
apancorb Oct 7, 2024
50d2250
feat(peg): add getProposedFederationSize Bridge Method
apancorb Oct 7, 2024
6e9c03f
Rename method that calculates amount to be sent in svp spend tx. Repl…
julia-zack Sep 26, 2024
578b631
feat(federation): add getProposedFederatorPublicKeyOfType method in F…
apancorb Oct 2, 2024
551971c
feat(peg): add getProposedFederatorPublicKeyOfType Bridge method
apancorb Oct 8, 2024
369c524
Remove duplicated method declaration in FederationSupport
marcos-iov Oct 8, 2024
a7e0e31
feat(peg): update test name in BridgeSupportTest
apancorb Oct 9, 2024
89dbcc7
Refactor addSignature as previous step to create addSvpSpendTxSignatu…
julia-zack Oct 3, 2024
4953554
Use getScriptSigWithSignature instead of updateScriptWithSignature
julia-zack Oct 8, 2024
1e760d6
Rename boolean method. Replace rskTxHashSerialized argument for the k…
julia-zack Oct 9, 2024
2ca29b7
Use already existing method to extract redeem script. Remove unnecess…
julia-zack Oct 11, 2024
e0a0d65
Throw exception when trying to serialize a null value. Move tests to …
julia-zack Oct 14, 2024
75e3925
Create addSvpSpendTxSignature method. Add tests. Rename method to mak…
julia-zack Oct 14, 2024
c778dcb
Update release tests
marcos-iov Oct 24, 2024
e2e6a8b
Add util method createRepository
marcos-iov Oct 24, 2024
ba5fd68
Fix wrong casting to log. Change proposed fed creation time to second…
julia-zack Nov 5, 2024
23809e2
Add intermediate method to improve svpIsOngoing readability
julia-zack Nov 6, 2024
752acee
Get rid of magic number being used for spend tx sent amount
julia-zack Nov 8, 2024
636fac8
Add missing import
marcos-iov Dec 5, 2024
d79424f
feat(peg): add function constants to Bridge for proposed federation
apancorb Oct 23, 2024
8b04939
Make logs a global variable and remove it from methods arguments. Cre…
julia-zack Oct 21, 2024
fff515f
Add unit test for new clearProposedFederation method
julia-zack Oct 23, 2024
a4b26fa
Improve naming and logs. Create clearSvpValues method in provider to …
julia-zack Oct 29, 2024
dfa32db
Create updateSvpState method and make all svp-related-methods private
julia-zack Oct 31, 2024
fb69565
Correct and make updateSvpState easier to follow
julia-zack Nov 13, 2024
3f4f449
Do not set last retired fed p2sh script in new commitFederation impl
julia-zack Nov 7, 2024
562ebc0
fix(peg): svp spend tx waiting for signatures double serialization
apancorb Nov 15, 2024
9a7658f
Do not set active federation creation block height before validation
julia-zack Nov 19, 2024
3919877
Modify public method to remove signatures for just returning the hash…
julia-zack Nov 19, 2024
3971513
Register spend transaction
julia-zack Nov 19, 2024
327f7ee
Create new registerSvpSpendTransaction method. Refactor to make code …
julia-zack Nov 20, 2024
5927242
Add test for getTxHashWithoutSigs using a real pegout. Minor refactor
julia-zack Nov 21, 2024
6f6a981
Create new public method in BridgeUtils to be reused
julia-zack Nov 20, 2024
866c3ff
Create new commitProposedFederation public method in fed support to b…
julia-zack Nov 20, 2024
ac5692c
Process svp success
julia-zack Nov 20, 2024
3e9b654
Refactor tests and improve comments
julia-zack Nov 21, 2024
574cf08
Reorder imports. Fix indentation
julia-zack Nov 22, 2024
2f755d8
Improve comment
julia-zack Nov 22, 2024
7b642b8
Add test cases when registering spend tx. Rollback moving method to B…
julia-zack Nov 22, 2024
379067d
Fix Sonar issues
julia-zack Nov 22, 2024
b3772a5
Create FederationContext class to hold info avout the currently live …
marcos-iov Nov 21, 2024
ee1eed4
Refactor logic in getRetiringFederation method to exit early
marcos-iov Nov 21, 2024
1abf342
Remove constructor from FederationContext only used in tests
marcos-iov Nov 21, 2024
842a273
Move javadoc from BridgeSupport to FederationSupport
marcos-iov Nov 21, 2024
4636a6e
Update PegUtils.getTransactionType to also identify SVP related trans…
marcos-iov Nov 21, 2024
99a04a5
Update registerBtcTransaction to consider SVP transaction types
marcos-iov Nov 21, 2024
dd06d5c
Fix broken tests in BridgeSupportFlyoverTest class
julia-zack Nov 22, 2024
5454d71
Add tests for FederationContext class
marcos-iov Nov 22, 2024
3b85c45
Refactor FederationContextTest
marcos-iov Nov 22, 2024
cdfaad7
Add tests for FederationSupport
marcos-iov Nov 22, 2024
f1a501a
Refactor test setup to make tests independent
marcos-iov Nov 22, 2024
c569f23
Fix tests. Add tests for fed context
julia-zack Nov 25, 2024
164ea2e
Fix svp tests that broke
julia-zack Nov 25, 2024
c590b4e
Minor refactor to make code cleaner
julia-zack Nov 28, 2024
cad5154
Reduce switch complexity to avoid sonar complain
julia-zack Nov 28, 2024
3071fed
feat(peg): enhance logging for svp protocol
apancorb Dec 2, 2024
cf318d6
feat(peg): save svp spend tx signature back to Bridge storage
apancorb Dec 2, 2024
eab0d82
feat(constants): increase svp validation period in regtest
apancorb Dec 2, 2024
dda54b7
refactor(peg): move comments
apancorb Dec 3, 2024
2467ab7
refactor(peg): move comments
apancorb Dec 3, 2024
882d468
Implement builder pattern in fed context
julia-zack Nov 28, 2024
31043c5
Rename to be consistent with other builders
julia-zack Dec 3, 2024
ee2b7fb
Simplify methods to register and process peg-in and peg-outs
marcos-iov Dec 4, 2024
a01a3e8
Rename processPegIn to registerPegIn
marcos-iov Dec 4, 2024
4de980d
Rename processPegoutOrMigration to registerNewUtxos
marcos-iov Dec 4, 2024
808ff7d
Add explanatory comment in registerSvpFundTx
marcos-iov Dec 4, 2024
4d19d8e
Refactor and simplify registerSvpSpendTx method
marcos-iov Dec 4, 2024
44eb9b6
Call registerNewUtxos method from executePegIn to save UTXOs and mark…
marcos-iov Dec 4, 2024
494fa85
Remove global variable svpSpendTransactionHashUnsigned from BridgeSup…
marcos-iov Dec 4, 2024
7d0c995
Add new method to assert svp success
marcos-iov Dec 4, 2024
fbf4246
Remove global variable svpFundTxHashUnsigned from BridgeSupportSvpTest
marcos-iov Dec 4, 2024
c2c95fc
Mark tx as processed after refund in legacyRegisterPegin
marcos-iov Dec 4, 2024
666dcfb
Register UTXOs and mark tx as processed in the same method
marcos-iov Dec 4, 2024
e468b02
Improve logging in registerBtcTransaction
marcos-iov Dec 5, 2024
8d052bc
Mark tx as processed for peg-in v1 rejected if locking cap is exceeded
marcos-iov Dec 5, 2024
ef61bc8
Return active and retiring feds creation time in seconds after lovell
julia-zack Dec 5, 2024
da04908
Remove logs that are no longer necessary since the tx type is being l…
julia-zack Dec 5, 2024
2ea98c0
Move tests to BridgeTest and use bridgeBuilder
julia-zack Dec 5, 2024
3c8ed99
Fix test
julia-zack Dec 6, 2024
f8e6eb0
refactor(constants): make FederationConstants an abstract class
apancorb Dec 4, 2024
abc203c
refactor(constants): make upper case for instance var
apancorb Dec 4, 2024
8b5d102
feat(constants): make federation regtest constants use a lazy singlet…
apancorb Dec 4, 2024
a77e611
refactor(constants): sort imports and upper case for static final var…
apancorb Dec 5, 2024
b9709f0
refactor(constants): default federation public keys for bridge regtest
apancorb Dec 5, 2024
df00504
feat(constants): add unit tests for lazy singleton pattern for federa…
apancorb Dec 5, 2024
1404873
feat(constants): add javadocs for lazy singletons in federation regte…
apancorb Dec 5, 2024
17d546b
feat(constants): move to fed regtest constants unit tests class
apancorb Dec 6, 2024
d3f2b00
Use clear methods instead of setting null values
julia-zack Dec 5, 2024
b794de7
Add tests for clearSvpFundTxHashUnsigned
marcos-iov Dec 9, 2024
73dbbc4
Add tests for clearSvpSpendTxHashUnsigned
marcos-iov Dec 9, 2024
7630a28
Add tests for clearSvpSpendTxWaitingForSignatures
marcos-iov Dec 9, 2024
5c9e371
Add tests for clearSvpFundTxSigned
marcos-iov Dec 9, 2024
e0c0cc6
Legacy peg in happy path (#2886)
julianlen Dec 16, 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
179 changes: 168 additions & 11 deletions rskj-core/src/main/java/co/rsk/peg/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package co.rsk.peg;

import static co.rsk.peg.BridgeSerializationUtils.deserializeRskTxHash;
import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP417;

import co.rsk.bitcoinj.core.*;
Expand All @@ -33,6 +34,7 @@
import co.rsk.peg.vote.ABICallSpec;
import co.rsk.peg.bitcoin.MerkleBranch;
import co.rsk.peg.federation.Federation;
import co.rsk.peg.federation.FederationChangeResponseCode;
import co.rsk.peg.federation.FederationMember;
import co.rsk.peg.flyover.FlyoverTxResponseCodes;
import co.rsk.peg.utils.BtcTransactionFormatUtils;
Expand Down Expand Up @@ -95,6 +97,8 @@ public class Bridge extends PrecompiledContracts.PrecompiledContract {
public static final CallTransaction.Function ADD_SIGNATURE = BridgeMethods.ADD_SIGNATURE.getFunction();
// Returns a StateForFederator encoded in RLP
public static final CallTransaction.Function GET_STATE_FOR_BTC_RELEASE_CLIENT = BridgeMethods.GET_STATE_FOR_BTC_RELEASE_CLIENT.getFunction();
// Returns a StateForProposedFederator encoded in RLP
public static final CallTransaction.Function GET_STATE_FOR_SVP_CLIENT = BridgeMethods.GET_STATE_FOR_SVP_CLIENT.getFunction();
// Returns a BridgeState encoded in RLP
public static final CallTransaction.Function GET_STATE_FOR_DEBUGGING = BridgeMethods.GET_STATE_FOR_DEBUGGING.getFunction();
// Return the bitcoin blockchain best chain height know by the bridge contract
Expand Down Expand Up @@ -152,6 +156,17 @@ public class Bridge extends PrecompiledContracts.PrecompiledContract {
// Returns the block number of the creation of the retiring federation
public static final CallTransaction.Function GET_RETIRING_FEDERATION_CREATION_BLOCK_NUMBER = BridgeMethods.GET_RETIRING_FEDERATION_CREATION_BLOCK_NUMBER.getFunction();

// Returns the proposed federation bitcoin address
public static final CallTransaction.Function GET_PROPOSED_FEDERATION_ADDRESS = BridgeMethods.GET_PROPOSED_FEDERATION_ADDRESS.getFunction();
// Returns the number of federates in the proposed federation
public static final CallTransaction.Function GET_PROPOSED_FEDERATION_SIZE = BridgeMethods.GET_PROPOSED_FEDERATION_SIZE.getFunction();
// Returns the public key of given type the federator at the specified index for the current proposed federation
public static final CallTransaction.Function GET_PROPOSED_FEDERATOR_PUBLIC_KEY_OF_TYPE = BridgeMethods.GET_PROPOSED_FEDERATOR_PUBLIC_KEY_OF_TYPE.getFunction();
// Returns the creation time of the proposed federation
public static final CallTransaction.Function GET_PROPOSED_FEDERATION_CREATION_TIME = BridgeMethods.GET_PROPOSED_FEDERATION_CREATION_TIME.getFunction();
// Returns the block number of the creation of the proposed federation
public static final CallTransaction.Function GET_PROPOSED_FEDERATION_CREATION_BLOCK_NUMBER = BridgeMethods.GET_PROPOSED_FEDERATION_CREATION_BLOCK_NUMBER.getFunction();

// Creates a new pending federation and returns its id
public static final CallTransaction.Function CREATE_FEDERATION = BridgeMethods.CREATE_FEDERATION.getFunction();
// Adds the given key to the current pending federation
Expand Down Expand Up @@ -614,14 +629,15 @@ public void addSignature(Object[] args) throws VMException {
}
signatures.add(signatureByteArray);
}
byte[] rskTxHash = (byte[]) args[2];
if (rskTxHash.length!=32) {
throw new BridgeIllegalArgumentException("Invalid rsk tx hash " + Bytes.of(rskTxHash));
byte[] rskTxHashSerialized = (byte[]) args[2];
Keccak256 rskTxHash;
try {
rskTxHash = deserializeRskTxHash(rskTxHashSerialized);
} catch (IllegalArgumentException e) {
throw new BridgeIllegalArgumentException("Invalid rsk tx hash " + Bytes.of(rskTxHashSerialized));
}
try {
bridgeSupport.addSignature(federatorPublicKey, signatures, rskTxHash);
} catch (BridgeIllegalArgumentException e) {
throw e;
} catch (Exception e) {
logger.warn("Exception in addSignature", e);
throw new VMException("Exception in addSignature", e);
Expand All @@ -639,6 +655,17 @@ public byte[] getStateForBtcReleaseClient(Object[] args) throws VMException {
}
}

public byte[] getStateForSvpClient(Object[] args) throws VMException {
logger.trace("getStateForSvpClient");

try {
return bridgeSupport.getStateForSvpClient();
} catch (Exception e) {
logger.warn("Exception in getStateForSvpClient", e);
throw new VMException("Exception in getStateForSvpClient", e);
}
}

public byte[] getStateForDebugging(Object[] args) throws VMException {
logger.trace("getStateForDebugging");

Expand Down Expand Up @@ -812,9 +839,15 @@ public byte[] getFederatorPublicKeyOfType(Object[] args) throws VMException {

public Long getFederationCreationTime(Object[] args) {
logger.trace("getFederationCreationTime");
Instant activeFederationCreationTime = bridgeSupport.getActiveFederationCreationTime();

// Return the creation time in milliseconds from the epoch
return bridgeSupport.getActiveFederationCreationTime().toEpochMilli();
if (!activations.isActive(ConsensusRule.RSKIP419)) {
// Return the creation time in milliseconds from the epoch
return activeFederationCreationTime.toEpochMilli();
}

// Return the creation time in seconds from the epoch
return activeFederationCreationTime.getEpochSecond();
}

public long getFederationCreationBlockNumber(Object[] args) {
Expand Down Expand Up @@ -887,15 +920,20 @@ public byte[] getRetiringFederatorPublicKeyOfType(Object[] args) throws VMExcept
public Long getRetiringFederationCreationTime(Object[] args) {
logger.trace("getRetiringFederationCreationTime");

Instant creationTime = bridgeSupport.getRetiringFederationCreationTime();
Instant retiringFederationCreationTime = bridgeSupport.getRetiringFederationCreationTime();

if (creationTime == null) {
if (retiringFederationCreationTime == null) {
// -1 is returned when no retiring federation
return -1L;
}

// Return the creation time in milliseconds from the epoch
return creationTime.toEpochMilli();
if (!activations.isActive(ConsensusRule.RSKIP419)) {
// Return the creation time in milliseconds from the epoch
return retiringFederationCreationTime.toEpochMilli();
}

// Return the creation time in seconds from the epoch
return retiringFederationCreationTime.getEpochSecond();
}

public long getRetiringFederationCreationBlockNumber(Object[] args) {
Expand Down Expand Up @@ -1027,6 +1065,125 @@ public byte[] getPendingFederatorPublicKeyOfType(Object[] args) throws VMExcepti
return publicKey;
}

/**
* Retrieves the proposed federation Bitcoin address as a Base58 string.
*
* <p>
* This method attempts to fetch the address of the proposed federation. If the
* proposed federation is present, it converts the address to its Base58 representation.
* If not, an empty string is returned.
* <p>
*
* @param args Additional arguments (currently unused)
* @return The Base58 encoded Bitcoin address of the proposed federation, or an empty
* string if no proposed federation is present.
*/
public String getProposedFederationAddress(Object[] args) {
logger.trace("getProposedFederationAddress");

return bridgeSupport.getProposedFederationAddress()
.map(Address::toBase58)
.orElse("");
}

/**
* Retrieves the size of the proposed federation, if it exists.
*
* <p>
* This method returns the number of members in the proposed federation. If no proposed federation exists,
* it returns a default response code {@link FederationChangeResponseCode#FEDERATION_NON_EXISTENT} that indicates
* the federation does not exist.
* </p>
*
* @param args unused arguments for this method (can be null or empty).
* @return the size of the proposed federation (number of members), or the default code from
* {@link FederationChangeResponseCode#FEDERATION_NON_EXISTENT} if no proposed federation is available.
*/
public int getProposedFederationSize(Object[] args) {
logger.trace("getProposedFederationSize");

return bridgeSupport.getProposedFederationSize()
.orElse(FederationChangeResponseCode.FEDERATION_NON_EXISTENT.getCode());
}

/**
* Retrieves the creation time of the proposed federation in seconds since the epoch.
*
* <p>
* This method checks if a proposed federation exists and returns its creation time in
* seconds since the Unix epoch. If no proposed federation exists, it returns -1.
* </p>
*
* @param args unused arguments for this method (can be null or empty).
* @return the creation time of the proposed federation in seconds since the epoch,
* or -1 if no proposed federation exists.
*/
public Long getProposedFederationCreationTime(Object[] args) {
logger.trace("getProposedFederationCreationTime");

return bridgeSupport.getProposedFederationCreationTime()
.map(Instant::getEpochSecond)
.orElse(-1L);
}

/**
* Retrieves the block number of the proposed federation's creation.
*
* <p>
* This method checks if a proposed federation exists and returns the block number at which it was created.
* If no proposed federation exists, it returns the default code defined in
* {@link FederationChangeResponseCode#FEDERATION_NON_EXISTENT}.
* </p>
*
* @param args unused arguments for this method (can be null or empty).
* @return the block number of the proposed federation's creation, or
* the code from {@link FederationChangeResponseCode#FEDERATION_NON_EXISTENT}
* if no proposed federation exists.
*/
public long getProposedFederationCreationBlockNumber(Object[] args) {
logger.trace("getProposedFederationCreationBlockNumber");

return bridgeSupport.getProposedFederationCreationBlockNumber()
.orElse((long) FederationChangeResponseCode.FEDERATION_NON_EXISTENT.getCode());
}

/**
* Retrieves the public key of the proposed federator at the specified index and key type.
*
* <p>
* This method extracts the index and key type from the provided arguments, retrieves the
* public key of the proposed federator, and returns it. If no public key is found, an empty byte
* array is returned.
* </p>
*
* <p>
* The first argument in the {@code args} array is expected to be a {@link BigInteger} representing
* the federator's index. The second argument is expected to be a {@link String} representing
* the key type, which is converted into a {@link FederationMember.KeyType}.
* </p>
*
* @param args an array of arguments, where {@code args[0]} is a {@link BigInteger} for the federator's index,
* and {@code args[1]} is a {@link String} for the key type.
* @return a byte array containing the federator's public key, or an empty byte array if not found.
* @throws VMException if an error occurs while processing the key type.
*/
public byte[] getProposedFederatorPublicKeyOfType(Object[] args) throws VMException {
logger.trace("getProposedFederatorPublicKeyOfType");

int index = ((BigInteger) args[0]).intValue();

FederationMember.KeyType keyType;
try {
keyType = FederationMember.KeyType.byValue((String) args[1]);
} catch (Exception e) {
logger.warn("Exception in getProposedFederatorPublicKeyOfType", e);
throw new VMException("Exception in getProposedFederatorPublicKeyOfType", e);
}

return bridgeSupport.getProposedFederatorPublicKeyOfType(index, keyType)
.orElse(new byte[]{});
}

public Integer getLockWhitelistSize(Object[] args) {
logger.trace("getLockWhitelistSize");

Expand Down
13 changes: 8 additions & 5 deletions rskj-core/src/main/java/co/rsk/peg/BridgeEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.ethereum.solidity.SolidityType;

public enum BridgeEvents {

LOCK_BTC("lock_btc", new CallTransaction.Param[] {
new CallTransaction.Param(true, Fields.RECEIVER, SolidityType.getType(SolidityType.ADDRESS)),
new CallTransaction.Param(false, Fields.BTC_TX_HASH, SolidityType.getType(SolidityType.BYTES32)),
Expand Down Expand Up @@ -44,6 +43,10 @@ public enum BridgeEvents {
new CallTransaction.Param(false, "newFederationBtcAddress", SolidityType.getType(SolidityType.STRING)),
new CallTransaction.Param(false, "activationHeight", SolidityType.getType(SolidityType.INT256))
}),
COMMIT_FEDERATION_FAILED("commit_federation_failed", new CallTransaction.Param[] {
new CallTransaction.Param(false, "proposedFederationRedeemScript", SolidityType.getType(SolidityType.BYTES)),
new CallTransaction.Param(false, "blockNumber", SolidityType.getType(SolidityType.INT256))
}),
RELEASE_REQUESTED("release_requested", new CallTransaction.Param[] {
new CallTransaction.Param(true, "rskTxHash", SolidityType.getType(SolidityType.BYTES32)),
new CallTransaction.Param(true, Fields.BTC_TX_HASH, SolidityType.getType(SolidityType.BYTES32)),
Expand Down Expand Up @@ -90,14 +93,14 @@ public CallTransaction.Function getEvent() {
}

private static class Fields {
private static final String RECEIVER = "receiver";
private static final String SENDER = "sender";
private static final String AMOUNT = "amount";
private static final String REASON = "reason";
private static final String BTC_DESTINATION_ADDRESS = "btcDestinationAddress";
private static final String BTC_TX_HASH = "btcTxHash";
private static final String REASON = "reason";
private static final String RECEIVER = "receiver";
private static final String RELEASE_RSK_TX_HASH = "releaseRskTxHash";
private static final String RELEASE_RSK_TX_HASHES = "releaseRskTxHashes";
private static final String SENDER = "sender";
private static final String UTXO_OUTPOINT_VALUES = "utxoOutpointValues";
private static final String BTC_DESTINATION_ADDRESS = "btcDestinationAddress";
}
}
Loading
Loading