Skip to content

Commit

Permalink
Merge pull request #108 from HorizenOfficial/pc/version_1_4_fork_pregobi
Browse files Browse the repository at this point in the history
Version 1.4 fork on pregobi
  • Loading branch information
paolocappelletti authored May 20, 2024
2 parents 203b6aa + c6c0261 commit 3ada115
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 23 deletions.
28 changes: 24 additions & 4 deletions doc/nativesc/contracts/ForgerStakesV2.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
"anonymous": false,
"inputs": [
{
"indexed": false,
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": true,
"indexed": false,
"internalType": "bytes32",
"name": "signPubKey",
"type": "bytes32"
Expand Down Expand Up @@ -648,13 +648,33 @@
},
{
"internalType": "bytes32",
"name": "signature1",
"name": "sign1_1",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "sign1_2",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "sign2_1",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "signature2",
"name": "sign2_2",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "sign2_3",
"type": "bytes32"
},
{
"internalType": "bytes1",
"name": "sign2_4",
"type": "bytes1"
}
],
"name": "updateForger",
Expand Down
16 changes: 11 additions & 5 deletions doc/nativesc/contracts/ForgerStakesV2.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ This native smart contract manages the forger stakes from EON 1.4.0 version.
address rewardAddress, bytes32 sign1_1, bytes32 sign1_2,
bytes32 sign2_1, bytes32 sign2_2, bytes32 sign2_3, bytes1 sign2_4) external payable;

Registers a new forger.
Register a new forger.
rewardShare can range in [0..1000] and can be 0 if and only if rewardAddress == 0x000..00.<br>
Vrf key and signatures are split in two or more separate parameters, being longer than 32 bytes.<br>
sign1_x are the 25519 signature chunks and sign2_x are the Vfr signature chunks.<br>
The message to sign is a string concatenation of signPubKey+vrfKey+rewardShare+rewardAddress, where rewardAddress
is represented in the Eip55 checksum format.<br>
The message to sign is the first 31 bytes of Keccak256 hash of a string formed by the concatenation
of signPubKey+vrfKey+rewardShare+rewardAddress. rewardAddress is represented in the Eip55
checksum format and hex strings are lowercase with no prefix.<br>
The method accepts WEI value: the sent value will be converted to the initial stake assigned to the forger.<br>
The initial stake amount must be >= min threshold (10 Zen)

Expand Down Expand Up @@ -59,11 +60,13 @@ This native smart contract manages the forger stakes from EON 1.4.0 version.
Returns the total stake amount, at the end of one or more consensus epochs, assigned to a specific forger.<br>
vrf, signKey and delegator are optional: if all are null, the total stake amount will be returned. If only
delegator is null, all the stakes assigned to the forger will be summed.<br>
Be aware that following convention applies when we talk about 'null' values: for bytes parameters, as addresses of key etc., a byte array of the expected length with all 0 values is interpreted as null, eg "0x0000000000000000000000000000000000000000" for addresses. For consensusEpochStart and maxNumOfEpoch, it is 0.<br>
If vrf and signKey are null, but delegator is defined, the method will fail.<br>
consensusEpochStart and maxNumOfEpoch are optional: if both null, the data at the current consensus epoch is returned.
Be aware that following convention applies when we talk about 'null' values: for bytes parameters, as addresses or keys etc., a byte array of the expected length with all 0 values is interpreted as null, eg "0x0000000000000000000000000000000000000000" for addresses.<br>
For consensusEpochStart and maxNumOfEpoch, it is 0.<br>
Returned array contains also elements with 0 value. Returned values are ordered by epoch, and the array length may
be < maxNumOfEpoch if the current consensus epoch is < (consensusEpochStart + maxNumOfEpoch - 1).
be < maxNumOfEpoch if the current consensus epoch is < (consensusEpochStart + maxNumOfEpoch).


- rewardsReceived

Expand Down Expand Up @@ -113,6 +116,7 @@ This native smart contract manages the forger stakes from EON 1.4.0 version.

Returns the paginated list of stakes delegated to a specific forger, grouped by delegator address.<br>
Each element of the list is the total amount delegated by a specific address. The data structure has the following format:<br>
The returned array length may be less than pageSize even if there are still additional elements because stakes with 0 amount are filtered out.

struct StakeDataDelegator {
address delegator;
Expand All @@ -127,6 +131,8 @@ This native smart contract manages the forger stakes from EON 1.4.0 version.

Returns the paginated list of stakes delegated by a specific address, grouped by forger.<br>
Each element of the list is the total amount delegated to a specific forger. The data structure has the following format:<br>
The returned array length may be less than pageSize even if there are still additional elements because stakes with 0 amount are filtered out.

struct StakeDataForger {
bytes32 signPubKey;
Expand Down
28 changes: 15 additions & 13 deletions doc/nativesc/contracts/ForgerStakesV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ interface ForgerStakesV2 {
// Event declaration
// Up to 3 parameters can be indexed.
// Indexed parameters help you filter the logs by the indexed parameter
event RegisterForger(address sender, bytes32 indexed signPubKey, bytes32 indexed vrf1, bytes1 indexed vrf2, uint256 value, uint32 rewardShare, address reward_address);
event UpdateForger(address indexed sender, bytes32 signPubKey, bytes32 indexed vrf1, bytes1 indexed vrf2, uint32 rewardShare, address reward_address);
event RegisterForger(address indexed sender, bytes32 signPubKey, bytes32 indexed vrf1, bytes1 indexed vrf2, uint256 value, uint32 rewardShare, address reward_address);
event UpdateForger(address indexed sender, bytes32 signPubKey, bytes32 indexed vrf1, bytes1 indexed vrf2, uint32 rewardShare, address reward_address);
event DelegateForgerStake(address indexed sender, bytes32 signPubKey, bytes32 indexed vrf1, bytes1 indexed vrf2, uint256 value);
event WithdrawForgerStake(address indexed sender, bytes32 signPubKey, bytes32 indexed vrf1, bytes1 indexed vrf2, uint256 value);
event ActivateStakeV2();
Expand Down Expand Up @@ -45,22 +45,24 @@ interface ForgerStakesV2 {
rewardShare can range in [0..1000] and can be 0 if and only if rewardAddress == 0x000..00.
Vrf key and signatures are split in two or more separate parameters, being longer than 32 bytes.
sign1_x are the 25519 signature chunks and sign2_x are the Vfr signature chunks.
The message to sign is a string concatenation of signPubKey+vrfKey+rewardShare+rewardAddress, where rewardAddress
is represented in the Eip55 checksum format.
The message to sign is the first 31 bytes of Keccak256 hash of a string formed by the concatenation
of signPubKey+vrfKey+rewardShare+rewardAddress. rewardAddress is represented in the Eip55
checksum format and hex strings are lowercase with no prefix.
The method accepts WEI value: the sent value will be converted to the initial stake assigned to the forger.
The initial stake amount must be >= min threshold (10 Zen)
*/
function registerForger(bytes32 signPubKey, bytes32 vrfKey1, bytes1 vrfKey2, uint32 rewardShare,
address rewardAddress, bytes32 sign1_1, bytes32 sign1_2,
bytes32 sign2_1, bytes32 sign2_2, bytes32 sign2_3, bytes1 sign2_4) external payable;


/*
Updates an existing forger.
A forger can be updated just once and only if rewardAddress == 0x000..00 and rewardShare == 0.
Vrf key is split in two separate parameters, being longer than 32 bytes.
See above the registerForger command for the parameters meaning.
*/
function updateForger(bytes32 signPubKey, bytes32 vrf1, bytes1 vrf2, uint32 rewardShare, address rewardAddress, bytes32 signature1, bytes32 signature2) external;
function updateForger(bytes32 signPubKey, bytes32 vrf1, bytes1 vrf2, uint32 rewardShare,
address rewardAddress, bytes32 sign1_1, bytes32 sign1_2,
bytes32 sign2_1, bytes32 sign2_2, bytes32 sign2_3, bytes1 sign2_4) external;

/*
Delegate a stake to a previously registered forger.
Expand All @@ -80,21 +82,19 @@ interface ForgerStakesV2 {
Returns the total stake amount, at the end of one or more consensus epochs, assigned to a specific forger.
vrf, signKey and delegator are optional: if all are null, the total stake amount will be returned. If only
delegator is null, all the stakes assigned to the forger will be summed.
Be aware that following convention apply when we talk about 'null' values: for bytes parameters, as addresses of key etc., a byte array of the expected length with all 0 values is interpreted as null, eg "0x0000000000000000000000000000000000000000" for addresses.
For consensusEpochStart and maxNumOfEpoch, it is 0.
If vrf and signKey are null, but delegator is defined, the method will fail.
consensusEpochStart and maxNumOfEpoch are optional: if both null, the data at the current consensus epoch is returned.
Be aware that following convention applies when we talk about 'null' values: for bytes parameters, as addresses or keys etc., a byte array of the expected length with all 0 values is interpreted as null, eg "0x0000000000000000000000000000000000000000" for addresses.
For consensusEpochStart and maxNumOfEpoch, it is 0.
Returned array contains also elements with 0 value. Returned values are ordered by epoch, and the array length may
be < maxNumOfEpoch if the current consensus epoch is < (consensusEpochStart + maxNumOfEpoch) or if the forger was
registered after consensusEpochStart.
be < maxNumOfEpoch if the current consensus epoch is < (consensusEpochStart + maxNumOfEpoch).
*/
function stakeTotal(bytes32 signPubKey, bytes32 vrf1, bytes1 vrf2, address delegator, uint32 consensusEpochStart, uint32 maxNumOfEpoch) external view returns (uint256[] memory listOfStakes);

/*
Return total sum paid to the forger reward_address at the end of one or more consensus epochs.
Returned array contains also elements with 0 value. Returned values are ordered by epoch, and the array length may
be < maxNumOfEpoch if the current consensus epoch is < (consensusEpochStart + maxNumOfEpoch) or if the forger was
registered after consensusEpochStart.
be < maxNumOfEpoch if the current consensus epoch is < (consensusEpochStart + maxNumOfEpoch).
*/
function rewardsReceived(bytes32 signPubKey, bytes32 vrf1, bytes1 vrf2, uint32 consensusEpochStart, uint32 maxNumOfEpoch) external view returns (uint256[] memory listOfRewards);

Expand All @@ -121,13 +121,15 @@ interface ForgerStakesV2 {
Returns the paginated list of stakes delegated to a specific forger, grouped by delegator address.
Each element of the list is the total amount delegated by a specific address.
nextIndex will contain the index of the next element not returned yet. If no element is still present, next will be -1.
The returned array length may be less than pageSize even if there are still additional elements because stakes with 0 amount are filtered out.
*/
function getPagedForgersStakesByForger(bytes32 signPubKey, bytes32 vrf1, bytes1 vrf2, int32 startIndex, int32 pageSize) external view returns (int32 nextIndex, StakeDataDelegator[] memory listOfDelegatorStakes);

/*
Returns the paginated list of stakes delegated by a specific address, grouped by forger.
Each element of the list is the total amount delegated to a specific forger.
nextIndex will contain the index of the next element not returned yet. If no element is still present, next will be -1.
The returned array length may be less than pageSize even if there are still additional elements because stakes with 0 amount are filtered out.
*/
function getPagedForgersStakesByDelegator(address delegator, int32 startIndex, int32 pageSize) external view returns (int32 nextIndex, StakeDataForger[] memory listOfForgerStakes);

Expand Down
2 changes: 1 addition & 1 deletion doc/nativesc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ They can be invoked as any standard smart contract with rpc method calls or (sta
Below a detailed list:

[WithdrawalRequests](/doc/nativesc/contracts/WithdrawalRequests.md)
[ForgerStakesV2](/doc/nativesc/contracts/ForgerStakes.md)
[ForgerStakesV2](/doc/nativesc/contracts/ForgerStakesV2.md)
[McAddrOwnerships](/doc/nativesc/contracts/McAddrOwnership.md)
[CertKeyRotation](/doc/nativesc/contracts/CertKeyRotation.md)

Expand Down
1 change: 1 addition & 0 deletions node/src/main/java/io/horizen/eon/EonForkConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public EonForkConfigurator(Optional<String> sidechainId) {
optionalSidechainForks.addAll(new F3Fork(sidechainId).getPairs());
optionalSidechainForks.addAll(new F4Fork(sidechainId).getPairs());
optionalSidechainForks.addAll(new F5Fork(sidechainId).getPairs());
optionalSidechainForks.addAll(new F6Fork(sidechainId).getPairs());
mandatorySidechainFork1 = new SidechainForkConsensusEpoch(0, 0, 0);
}

Expand Down
52 changes: 52 additions & 0 deletions node/src/main/java/io/horizen/eon/forks/F6Fork.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.horizen.eon.forks;

import io.horizen.account.fork.Version1_3_0Fork;
import io.horizen.account.fork.Version1_4_0Fork;
import io.horizen.fork.OptionalSidechainFork;
import io.horizen.fork.SidechainForkConsensusEpoch;
import io.horizen.utils.Pair;

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

/**
* EON fork 6 (introduced in Version 1.4.0)
* New on-chain delegated staking reward mechanism, new handling of rewards from mainchain
*/
public class F6Fork extends EONFork {
public F6Fork(Optional<String> sidechainId) {
super(sidechainId);
}

@Override
protected int getActivationRegtest() {
return 7;
}
@Override
protected int getActivationTestnetPregobi() {return 2180;} //estimated start at TUE 21 May 2024 16:31 Milano time

@Override
protected int getActivationTestnetGobi() {
return 10000000; //TBD
}
@Override
protected int getActivationTestnet() { return 2180; //not used
}
@Override
protected int getActivationMainnet() {
return 10000000; //TBD
}

@Override
public List<Pair<SidechainForkConsensusEpoch, OptionalSidechainFork>> getPairs() {
return List.of(
new Pair<>(
new SidechainForkConsensusEpoch(
getActivationRegtest(),
getActivationTestnet(sidechainId),
getActivationMainnet()),
new Version1_4_0Fork(true)
)
);
}
}

0 comments on commit 3ada115

Please sign in to comment.