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 #2926

Draft
wants to merge 228 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
228 commits
Select commit Hold shift + click to select a range
7a3d37f
Add rskip419 config to lovell
julia-zack Jul 18, 2024
fdcbff1
Add validation period duration to federation constants
julia-zack Jul 18, 2024
c8c3974
Add proposedFederation and validationFundTxHashUnsigned
julia-zack Jul 18, 2024
02c7a9e
Add keys to storage index
julia-zack Jul 18, 2024
321077a
Add set and save methods for the proposed federation
julia-zack Jul 18, 2024
1f49b15
Save proposed federation with its own format version
julia-zack Jul 22, 2024
d3c5b6a
Add tests for saveProposedFederation method
julia-zack Jul 31, 2024
3e43647
Add format version assertion to tests
julia-zack Jul 31, 2024
baaba6f
Add getProposedFederation method
julia-zack Jul 31, 2024
ffacf62
Adds setFundTransactionUnsignedHash and saveFundTransactionUnsignedHa…
jeremy-then Jul 29, 2024
26aba2b
Add set and save methods for the proposed federation
julia-zack Jul 18, 2024
d3b78b2
Save null version when proposed federation is null
julia-zack Jul 23, 2024
ba39557
Add getProposedFederation method
julia-zack Jul 31, 2024
e244de4
Throw exception when there is no storage version for non-null propose…
julia-zack Aug 1, 2024
dfd388b
Adds setFundTransactionUnsignedHash and saveFundTransactionUnsignedHa…
jeremy-then Jul 29, 2024
e58345f
Adds getSvpFundTransactionUnsignedHash and tests
jeremy-then Aug 5, 2024
d5dcbdc
Split commit federation. Disable failing test
julia-zack Jul 31, 2024
4eeb34b
Add tests to existing nested class
julia-zack Aug 8, 2024
5b35d59
Comment broken test that be addressed later
julia-zack Aug 8, 2024
312f82b
Move svp fund tx hash unsigned entry from federation storage index ke…
julia-zack Aug 13, 2024
3708b7d
Remove svp fund tx logic from federation storage provider, and add it…
julia-zack Aug 13, 2024
8b5f835
Define spendable value directly in BridgeConstants
julia-zack Aug 15, 2024
344ecaf
Add getProposedFederation method in FederationSupport
julia-zack Aug 15, 2024
f7c39f2
Add proposed federation dummy flyover prefix to bridge constants
julia-zack Aug 19, 2024
7ba243d
Create new settleReleaseRequest method to perform common actions when…
julia-zack Aug 19, 2024
537a061
Add svp fund tx hash signed storage index key
julia-zack Aug 19, 2024
d8b0f66
Add set and save methods
julia-zack Aug 19, 2024
cc43f1f
Add getSvpFundTxHashSigned method
julia-zack Aug 19, 2024
e1db3f7
Move vote federation change nested test class to its own file
julia-zack Aug 19, 2024
09640d4
Add tests
julia-zack Aug 15, 2024
4214e15
Add flyover output to fund tx. Refactor
julia-zack Aug 16, 2024
2024dca
Add reused method to PegUtils
julia-zack Aug 16, 2024
b9b332d
Take nested SvpTests out of nested locking cap tests
julia-zack Aug 16, 2024
90f2d33
Use flyover rs builder. Remove method from PegUtils
julia-zack Aug 19, 2024
2a790d5
Create output to federation with flyover prefix with address instead …
julia-zack Aug 21, 2024
882b0bd
Add test for insufficient money exception test.
julia-zack Aug 21, 2024
185dfc5
Call new method for FlyoverRedeemScriptBuilder
marcos-iov Sep 17, 2024
90ecfe2
feat(peg): add svp spend tx hash unsigned storage entry
apancorb Aug 28, 2024
4eb12c0
feat(peg): add set and save storage methods for svp spend unsigned tx…
apancorb Aug 29, 2024
1fef4c8
feat(peg): add getter for svp spend tx hash
apancorb Aug 30, 2024
6109afc
feat(peg): add serialize and deserialize map logic with tests
apancorb Sep 2, 2024
f4344af
feat(peg): add svp spend tx waiting for signatures data structure
apancorb Sep 2, 2024
d251928
refactor(peg): change serialization naming for rsk txs waiting for si…
apancorb Sep 3, 2024
b664c5b
Create method to remove signatures from script sig
julia-zack Sep 5, 2024
ebf3d7f
Add methods to create a real valid chain with stored blocks to avoid …
julia-zack Sep 10, 2024
f64e644
Add method to check if svp is ongoing
julia-zack Sep 5, 2024
a6ef96d
feat(peg): add svp spend tx waiting for signatures storage key
apancorb Sep 11, 2024
559feff
feat(peg): add logic to save svp spend tx waiting for signatures with…
apancorb Sep 11, 2024
b26f189
feat(peg): allow null default entry for resetting svp spend tx waitin…
apancorb Sep 12, 2024
c833929
feat(peg): if empty svp spend tx waiting for signatures attempted to …
apancorb Sep 13, 2024
67ad629
fix(peg): fix error message in svp spend tx waiting for signatures ex…
apancorb Sep 13, 2024
7dcd7df
feat(peg): add null key and value for svp spend tx waiting for signat…
apancorb Sep 13, 2024
2ed91f5
feat(peg): add setter for svp spend tx waiting for signatures field i…
apancorb Sep 16, 2024
718e33a
Move svpSpendTxWaitingForSignatures validation to set method
marcos-iov Sep 16, 2024
62cdf89
feat(peg): add get svp spend tx waiting for signatures logic and unit…
apancorb Sep 13, 2024
415b603
Move flyover methods from BridgeSupport to PegUtils
julia-zack Sep 17, 2024
c7d9ad0
Create new methods to handle btc tx deserialization without inputs to…
julia-zack Sep 17, 2024
631e22e
When signed, save the svp fund tx instead of its hash
julia-zack Sep 16, 2024
89c7d34
refactor(peg): state for federator refactor including tests
apancorb Sep 19, 2024
8a6da8b
feat(peg): add state for proposed federator
apancorb Sep 19, 2024
a0b9823
feat(peg): add deserialization logic for federator states
apancorb Sep 20, 2024
576a046
feat(peg): simplify state for federator tests and add state for feder…
apancorb Sep 20, 2024
8aae6e7
Add tests for registering the svp fund transaction through registerBt…
julia-zack Sep 12, 2024
edad817
Add test for svp transaction without output change
julia-zack Sep 16, 2024
a5deea3
Adapt to have the svp fund tx signed instead of the hash
julia-zack Sep 16, 2024
92e13e9
Consider segwit transactions too when checking for svp fund transacti…
julia-zack Sep 23, 2024
e65214c
Simplify transaction hash comparison for svp fund transaction
julia-zack Sep 23, 2024
66bfe8e
Use Optional API to make code more concise and functional. Wrap long …
julia-zack Sep 24, 2024
4bad3ef
Move test for svp fund tx registration to BridgeSupportRegisterBtcTra…
julia-zack Sep 25, 2024
09aa84c
Move svp fund transaction tests to new FederationChangeTest class
julia-zack Sep 25, 2024
65a3a89
Rename test file
julia-zack Sep 25, 2024
91b36c2
feat(peg): add getStateForSvpClient Bridge method
apancorb Sep 23, 2024
6b2adc9
fix(peg): fix issue with serializing RLP list twice
apancorb Sep 23, 2024
d72ff9b
chore(peg): todo comment for fixed cost value
apancorb Sep 24, 2024
3a488db
feat(peg): add type safety for bridge method getStateForSvpClient
apancorb Sep 24, 2024
212a492
feat(peg): rollback to include current serialization logic for state …
apancorb Sep 26, 2024
65798bc
Move searchForOutput method to BitcoinUtils to reuse it
julia-zack Sep 25, 2024
c687393
Create and process svp spend transaction
julia-zack Sep 25, 2024
24f8d7e
Add tests to spend transaction process. Refactor some methods to avoi…
julia-zack Sep 26, 2024
4bd1c71
Create new method in BitcoinUtils to remove duplicated code from Brid…
julia-zack Sep 26, 2024
aa9eb63
Add hsm-needed pegout logging for svp spend tx. Remove duplicated code
julia-zack Sep 26, 2024
e61b0aa
Add assertions to new logged events. Reorder methods to be more organ…
julia-zack Sep 26, 2024
9bf5b02
Refactor method to avoid throwing exception unnecessary. Rename metho…
julia-zack Sep 26, 2024
f26759e
Rename method that calculates amount to be sent in svp spend tx. Repl…
julia-zack Sep 26, 2024
7317c73
Add missing empty p2sh input script to svp spend transaction
julia-zack Sep 30, 2024
82ed8d5
Add tests to check if svp spend tx inputs have expected script sig
julia-zack Oct 1, 2024
207a4ca
Refactor BridgeEventLoggerImpl
julia-zack Sep 27, 2024
24dd9f5
Refactor BridgeEventLoggerImpl to not receive SignatureCache object
marcos-iov Sep 27, 2024
2c23076
Remove unnecessary (since we are unit-testing) arguments from asserti…
julia-zack Sep 27, 2024
8572561
feat(federation): add getProposedFederationAddress method to Federati…
apancorb Oct 2, 2024
88131e8
feat(federation): add getProposedFederationSize to Federation Support
apancorb Oct 2, 2024
dc0cd53
Create new commitFederationFailed Bridge event
julia-zack Sep 27, 2024
d5ef3e8
Add test for logCommitFederationFailure from deprecated logger
julia-zack Oct 1, 2024
517305a
Move rsk block creation method to RskTestUtils
julia-zack Oct 3, 2024
0ecb890
Remove unnecessary suffix from variable name
julia-zack Oct 3, 2024
b7d1c53
Create default implementation of createRskBlock util method
marcos-iov Oct 3, 2024
a90a3f2
feat(federation): add getProposedFederationCreationTime in Federation…
apancorb Oct 2, 2024
e4c44a2
feat(federation): add getProposedFederationCreationBlockNumber method…
apancorb Oct 2, 2024
890f70b
feat(peg): add getProposedFederationAddress Bridge method
apancorb Oct 3, 2024
3332421
feat(peg): Update Bridge
apancorb Oct 4, 2024
c43920a
feat(federation): add getProposedFederatorPublicKeyOfType method in F…
apancorb Oct 2, 2024
6be09d7
refactor(federation): tidy up federation builder
apancorb Oct 3, 2024
c47ec64
feat(federation): add more unit tests per key type when empty federation
apancorb Oct 4, 2024
83b2782
feat(federation): add javadoc for getProposedFederationCreationTime i…
apancorb Oct 7, 2024
6265f61
feat(peg): add getProposedFederationCreationTime Bridge method
apancorb Oct 7, 2024
dc9c2d4
feat(federation): add javadoc for getProposedFederationCreationBlockN…
apancorb Oct 7, 2024
e355b3a
feat(peg): add getProposedFederationCreationBlockNumber Bridge Method
apancorb Oct 7, 2024
6affca4
feat(federation): add javadoc for getProposedFederationSize in Federa…
apancorb Oct 7, 2024
9b9c54a
feat(peg): add getProposedFederationSize Bridge Method
apancorb Oct 7, 2024
973f306
Rename method that calculates amount to be sent in svp spend tx. Repl…
julia-zack Sep 26, 2024
7d39bd5
feat(federation): add getProposedFederatorPublicKeyOfType method in F…
apancorb Oct 2, 2024
b86a249
feat(peg): add getProposedFederatorPublicKeyOfType Bridge method
apancorb Oct 8, 2024
0de37e5
Remove duplicated method declaration in FederationSupport
marcos-iov Oct 8, 2024
fb38515
feat(peg): update test name in BridgeSupportTest
apancorb Oct 9, 2024
137a270
Refactor addSignature as previous step to create addSvpSpendTxSignatu…
julia-zack Oct 3, 2024
bb51aed
Use getScriptSigWithSignature instead of updateScriptWithSignature
julia-zack Oct 8, 2024
267078a
Rename boolean method. Replace rskTxHashSerialized argument for the k…
julia-zack Oct 9, 2024
f04bf7f
Use already existing method to extract redeem script. Remove unnecess…
julia-zack Oct 11, 2024
e6557bd
Throw exception when trying to serialize a null value. Move tests to …
julia-zack Oct 14, 2024
1bd9727
Create addSvpSpendTxSignature method. Add tests. Rename method to mak…
julia-zack Oct 14, 2024
b0eb223
Update release tests
marcos-iov Oct 24, 2024
3c171f7
Add util method createRepository
marcos-iov Oct 24, 2024
4669c7a
Fix wrong casting to log. Change proposed fed creation time to second…
julia-zack Nov 5, 2024
49aeb45
Add intermediate method to improve svpIsOngoing readability
julia-zack Nov 6, 2024
1a20f79
Get rid of magic number being used for spend tx sent amount
julia-zack Nov 8, 2024
61dab4c
Add missing import
marcos-iov Dec 5, 2024
afb2a43
feat(peg): add function constants to Bridge for proposed federation
apancorb Oct 23, 2024
e87cc68
Make logs a global variable and remove it from methods arguments. Cre…
julia-zack Oct 21, 2024
aa31cb8
Add unit test for new clearProposedFederation method
julia-zack Oct 23, 2024
aeac614
Improve naming and logs. Create clearSvpValues method in provider to …
julia-zack Oct 29, 2024
bc4df1c
Create updateSvpState method and make all svp-related-methods private
julia-zack Oct 31, 2024
6eec5ca
Correct and make updateSvpState easier to follow
julia-zack Nov 13, 2024
aa33ed6
Do not set last retired fed p2sh script in new commitFederation impl
julia-zack Nov 7, 2024
6e12a55
fix(peg): svp spend tx waiting for signatures double serialization
apancorb Nov 15, 2024
89e43d0
Do not set active federation creation block height before validation
julia-zack Nov 19, 2024
72616eb
Modify public method to remove signatures for just returning the hash…
julia-zack Nov 19, 2024
38839b9
Register spend transaction
julia-zack Nov 19, 2024
06597ec
Create new registerSvpSpendTransaction method. Refactor to make code …
julia-zack Nov 20, 2024
be2a967
Add test for getTxHashWithoutSigs using a real pegout. Minor refactor
julia-zack Nov 21, 2024
87949c8
Create new public method in BridgeUtils to be reused
julia-zack Nov 20, 2024
e164d94
Create new commitProposedFederation public method in fed support to b…
julia-zack Nov 20, 2024
6c50cb3
Process svp success
julia-zack Nov 20, 2024
426b584
Refactor tests and improve comments
julia-zack Nov 21, 2024
1c8c63c
Reorder imports. Fix indentation
julia-zack Nov 22, 2024
5f09ae2
Improve comment
julia-zack Nov 22, 2024
e981cb9
Add test cases when registering spend tx. Rollback moving method to B…
julia-zack Nov 22, 2024
4dfc9e6
Fix Sonar issues
julia-zack Nov 22, 2024
bd9bd6e
Create FederationContext class to hold info avout the currently live …
marcos-iov Nov 21, 2024
a2c339a
Refactor logic in getRetiringFederation method to exit early
marcos-iov Nov 21, 2024
39ede54
Remove constructor from FederationContext only used in tests
marcos-iov Nov 21, 2024
d9b0085
Move javadoc from BridgeSupport to FederationSupport
marcos-iov Nov 21, 2024
1d35552
Update PegUtils.getTransactionType to also identify SVP related trans…
marcos-iov Nov 21, 2024
ea7cd47
Update registerBtcTransaction to consider SVP transaction types
marcos-iov Nov 21, 2024
0c8626e
Fix broken tests in BridgeSupportFlyoverTest class
julia-zack Nov 22, 2024
a21eecb
Add tests for FederationContext class
marcos-iov Nov 22, 2024
dc8c1a7
Refactor FederationContextTest
marcos-iov Nov 22, 2024
c72b5cd
Add tests for FederationSupport
marcos-iov Nov 22, 2024
228b41e
Refactor test setup to make tests independent
marcos-iov Nov 22, 2024
1b577d3
Fix tests. Add tests for fed context
julia-zack Nov 25, 2024
0322aa5
Fix svp tests that broke
julia-zack Nov 25, 2024
bac5bab
Minor refactor to make code cleaner
julia-zack Nov 28, 2024
bae46ff
Reduce switch complexity to avoid sonar complain
julia-zack Nov 28, 2024
4287aab
feat(peg): enhance logging for svp protocol
apancorb Dec 2, 2024
32ad5a1
feat(peg): save svp spend tx signature back to Bridge storage
apancorb Dec 2, 2024
6db74e4
feat(constants): increase svp validation period in regtest
apancorb Dec 2, 2024
cdf365a
refactor(peg): move comments
apancorb Dec 3, 2024
75392e4
refactor(peg): move comments
apancorb Dec 3, 2024
d4241b0
Implement builder pattern in fed context
julia-zack Nov 28, 2024
8c780d4
Rename to be consistent with other builders
julia-zack Dec 3, 2024
8915bfd
Simplify methods to register and process peg-in and peg-outs
marcos-iov Dec 4, 2024
b2fd04f
Rename processPegIn to registerPegIn
marcos-iov Dec 4, 2024
f9aa6f9
Rename processPegoutOrMigration to registerNewUtxos
marcos-iov Dec 4, 2024
4b935ee
Add explanatory comment in registerSvpFundTx
marcos-iov Dec 4, 2024
57bfe37
Refactor and simplify registerSvpSpendTx method
marcos-iov Dec 4, 2024
4241339
Call registerNewUtxos method from executePegIn to save UTXOs and mark…
marcos-iov Dec 4, 2024
a5ad276
Remove global variable svpSpendTransactionHashUnsigned from BridgeSup…
marcos-iov Dec 4, 2024
a274b80
Add new method to assert svp success
marcos-iov Dec 4, 2024
888e317
Remove global variable svpFundTxHashUnsigned from BridgeSupportSvpTest
marcos-iov Dec 4, 2024
4717b28
Mark tx as processed after refund in legacyRegisterPegin
marcos-iov Dec 4, 2024
8a5debf
Register UTXOs and mark tx as processed in the same method
marcos-iov Dec 4, 2024
2914ed6
Improve logging in registerBtcTransaction
marcos-iov Dec 5, 2024
f2da8f5
Mark tx as processed for peg-in v1 rejected if locking cap is exceeded
marcos-iov Dec 5, 2024
b5b6e75
Return active and retiring feds creation time in seconds after lovell
julia-zack Dec 5, 2024
2b0406e
Remove logs that are no longer necessary since the tx type is being l…
julia-zack Dec 5, 2024
9b182cc
Move tests to BridgeTest and use bridgeBuilder
julia-zack Dec 5, 2024
b0c014a
Fix test
julia-zack Dec 6, 2024
c3b2785
refactor(constants): make FederationConstants an abstract class
apancorb Dec 4, 2024
9d656b4
refactor(constants): make upper case for instance var
apancorb Dec 4, 2024
0617c06
feat(constants): make federation regtest constants use a lazy singlet…
apancorb Dec 4, 2024
50d7d86
refactor(constants): sort imports and upper case for static final var…
apancorb Dec 5, 2024
dd5fd63
refactor(constants): default federation public keys for bridge regtest
apancorb Dec 5, 2024
d248b17
feat(constants): add unit tests for lazy singleton pattern for federa…
apancorb Dec 5, 2024
deac9b9
feat(constants): add javadocs for lazy singletons in federation regte…
apancorb Dec 5, 2024
6a4d6b6
feat(constants): move to fed regtest constants unit tests class
apancorb Dec 6, 2024
1b3064f
Use clear methods instead of setting null values
julia-zack Dec 5, 2024
4433084
Add tests for clearSvpFundTxHashUnsigned
marcos-iov Dec 9, 2024
62e3948
Add tests for clearSvpSpendTxHashUnsigned
marcos-iov Dec 9, 2024
1a84264
Add tests for clearSvpSpendTxWaitingForSignatures
marcos-iov Dec 9, 2024
914a7ac
Add tests for clearSvpFundTxSigned
marcos-iov Dec 9, 2024
4bd6364
Use FederationChangeFunctions enum when voting
julia-zack Dec 18, 2024
d64bc12
Refactor to use new java17 switch
julia-zack Dec 19, 2024
b4a07e8
Remove wrong comment. Store call spec public keys arguments in a vari…
julia-zack Jan 6, 2025
0df06af
Remove validationPeriodIsOngoing method
julia-zack Dec 23, 2024
01a58fd
Make code more functional
julia-zack Jan 2, 2025
de24577
Create method to remove utxos used for a release transaction
julia-zack Jan 3, 2025
656908b
Fix the amount being send in svpSpendTx
julia-zack Jan 7, 2025
57d3582
Rename. Make log more accurate
julia-zack Jan 7, 2025
0e9324f
Remove unnecessary tests
julia-zack Jan 7, 2025
e772f46
Get active federation utxos directly
julia-zack Jan 7, 2025
151f415
Clean svp values not being get in execution time
julia-zack Jan 7, 2025
5e899ab
Reuse already declared global variable for spend tx creation hash
julia-zack Jan 8, 2025
351f431
Set info as logging level. Move svp cleaning logs to each specific me…
julia-zack Jan 8, 2025
e260062
Update testnet validation period duration and activation age
julia-zack Dec 23, 2024
d4da76e
Refactor activations name to use hf instead of rskip
julia-zack Jan 2, 2025
944b3f3
Refactor federation constants
marcos-iov Jan 8, 2025
4558f39
Add missing RSKIP419 to expected.conf file
marcos-iov Jan 8, 2025
68a38cf
Remove spendableValueFromProposedFed constant and use minPegoutTxValu…
julia-zack Jan 8, 2025
cefb90e
Add comment
julia-zack Jan 9, 2025
e4fb4c3
Do not shuffle fundTx outputs order
julia-zack Jan 8, 2025
ed6d032
Merge pull request #2918 from rsksmart/simplify_value_sent_in_fundTx
marcos-iov Jan 9, 2025
0f4a2a6
Merge pull request #2919 from rsksmart/fix_outputs_order_in_fundTx
marcos-iov Jan 9, 2025
4dd7d47
Rollback fundtx value change
julia-zack Jan 9, 2025
d1d3af9
Add missing blank line
julia-zack Jan 9, 2025
d8dd412
Fix test
julia-zack Jan 9, 2025
3c53d39
Merge pull request #2924 from rsksmart/rollback_change_in_fundTx_value
marcos-iov Jan 10, 2025
c0de479
Remove assert methods that do not return void
julia-zack Jan 9, 2025
89266ea
Merge pull request #2921 from rsksmart/refactor_svp_tests
marcos-iov Jan 10, 2025
8f3af1d
Merge pull request #2917 from rsksmart/feature/powpeg_validation_prot…
marcos-iov Jan 10, 2025
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