From e68aa746d0050aebb092f24123b257ac181455e3 Mon Sep 17 00:00:00 2001 From: buddho Date: Tue, 21 Nov 2023 17:17:10 +0800 Subject: [PATCH 1/4] improve rewards limit for fast finality (#419) --- contracts/BSCValidatorSet.sol | 2 +- contracts/SlashIndicator.sol | 2 +- contracts/SystemReward.sol | 17 ++++++++++++++++- contracts/TokenHub.sol | 4 ++++ contracts/interface/ISystemReward.sol | 1 + 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index 7f4d78db..85e6d592 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -561,7 +561,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica return; } - totalValue = ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(payable(address(this)), totalValue); + totalValue = ISystemReward(SYSTEM_REWARD_ADDR).claimRewardsforFinality(payable(address(this)), totalValue); if (totalValue == 0) { return; } diff --git a/contracts/SlashIndicator.sol b/contracts/SlashIndicator.sol index a2056d55..4d4b78c3 100644 --- a/contracts/SlashIndicator.sol +++ b/contracts/SlashIndicator.sol @@ -228,7 +228,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication for (uint i; i < voteAddrs.length; ++i) { if (BytesLib.equal(voteAddrs[i], _evidence.voteAddr)) { uint256 amount = (address(SYSTEM_REWARD_ADDR).balance * finalitySlashRewardRatio) / 100; - ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(msg.sender, amount); + ISystemReward(SYSTEM_REWARD_ADDR).claimRewardsforFinality(msg.sender, amount); IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony( vals[i]); break; } diff --git a/contracts/SystemReward.sol b/contracts/SystemReward.sol index 7669d23f..26f29eca 100644 --- a/contracts/SystemReward.sol +++ b/contracts/SystemReward.sol @@ -6,7 +6,8 @@ import "./interface/IParamSubscriber.sol"; import "./interface/ISystemReward.sol"; contract SystemReward is System, IParamSubscriber, ISystemReward { - uint256 public constant MAX_REWARDS = 1e18; + uint256 public constant MAX_REWARDS/*_FOR_RELAYER*/ = 1e18; + uint256 public constant MAX_REWARDS_FOR_FINALITY = 5e18; uint public numOperator; mapping(address => bool) operators; @@ -53,6 +54,20 @@ contract SystemReward is System, IParamSubscriber, ISystemReward { return actualAmount; } + function claimRewardsforFinality(address payable to, uint256 amount) external override(ISystemReward) doInit onlyOperator returns (uint256) { + uint256 actualAmount = amount < address(this).balance ? amount : address(this).balance; + if (actualAmount > MAX_REWARDS_FOR_FINALITY) { + actualAmount = MAX_REWARDS_FOR_FINALITY; + } + if (actualAmount != 0) { + to.transfer(actualAmount); + emit rewardTo(to, actualAmount); + } else { + emit rewardEmpty(); + } + return actualAmount; + } + function isOperator(address addr) external view returns (bool) { return operators[addr]; } diff --git a/contracts/TokenHub.sol b/contracts/TokenHub.sol index cc4904b1..0bb22eb2 100644 --- a/contracts/TokenHub.sol +++ b/contracts/TokenHub.sol @@ -161,6 +161,10 @@ contract TokenHub is ITokenHub, System, IParamSubscriber, IApplication, ISystemR return actualAmount; } + function claimRewardsforFinality(address payable, uint256) onlyInit onlyRelayerIncentivize external override returns(uint256) { + revert("CLAIM_REWARDS_FOR_FINALITY_NOT_ALLOWED"); + } + function getMiniRelayFee() external view override returns(uint256) { return relayFee; } diff --git a/contracts/interface/ISystemReward.sol b/contracts/interface/ISystemReward.sol index 67a71f58..4e127df6 100644 --- a/contracts/interface/ISystemReward.sol +++ b/contracts/interface/ISystemReward.sol @@ -2,4 +2,5 @@ pragma solidity 0.6.4; interface ISystemReward { function claimRewards(address payable to, uint256 amount) external returns(uint256 actualAmount); + function claimRewardsforFinality(address payable to, uint256 amount) external returns(uint256 actualAmount); } \ No newline at end of file From ff75c61ecd457c1370327e136b38c7a0d63ca821 Mon Sep 17 00:00:00 2001 From: buddho Date: Tue, 21 Nov 2023 18:13:59 +0800 Subject: [PATCH 2/4] keep burn ratio in BEP-95 (#421) --- contracts/BSCValidatorSet.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/BSCValidatorSet.sol b/contracts/BSCValidatorSet.sol index 85e6d592..c3482ec6 100644 --- a/contracts/BSCValidatorSet.sol +++ b/contracts/BSCValidatorSet.sol @@ -56,7 +56,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica uint256 public constant BURN_RATIO_SCALE = 10000; address public constant BURN_ADDRESS = 0x000000000000000000000000000000000000dEaD; - uint256 public constant INIT_BURN_RATIO = 0; // deprecated + uint256 public constant INIT_BURN_RATIO = 1000; uint256 public burnRatio; bool public burnRatioInitialized; // deprecated @@ -229,7 +229,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica if (isSystemRewardIncluded == false){ systemRewardRatio = INIT_SYSTEM_REWARD_RATIO; - burnRatio = 938; // 15/16*10% is 9.375% + burnRatio = INIT_BURN_RATIO; isSystemRewardIncluded = true; } From 4c6d2fd63c601e64784c7eac6e55eb340450fd72 Mon Sep 17 00:00:00 2001 From: buddho Date: Wed, 22 Nov 2023 18:04:33 +0800 Subject: [PATCH 3/4] init SystemReward for local test and add shanghaiTime,keplerTime (#422) --- genesis-template.json | 3 ++- scripts/generate-tendermintLightClient.sh | 13 +++++++++++++ scripts/generate.sh | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/genesis-template.json b/genesis-template.json index 6c5f8ad6..9e765410 100644 --- a/genesis-template.json +++ b/genesis-template.json @@ -24,7 +24,8 @@ "berlinBlock": 8, "londonBlock": 8, "hertzBlock": 8, - "fusionBlock": 9, + "shanghaiTime": 0, + "keplerTime": 0, "parlia": { "period": 3, "epoch": 200 diff --git a/scripts/generate-tendermintLightClient.sh b/scripts/generate-tendermintLightClient.sh index c8538094..15362d83 100644 --- a/scripts/generate-tendermintLightClient.sh +++ b/scripts/generate-tendermintLightClient.sh @@ -2,12 +2,17 @@ # Default values OUTPUT="./contracts/TendermintLightClient.sol" +NETWORK="" INIT_CONSENSUS_STATE_BYTES="696e616e63652d436861696e2d4e696c650000000000000000000000000000000000000000000229eca254b3859bffefaf85f4c95da9fbd26527766b784272789c30ec56b380b6eb96442aaab207bc59978ba3dd477690f5c5872334fc39e627723daa97e441e88ba4515150ec3182bc82593df36f8abb25a619187fcfab7e552b94e64ed2deed000000e8d4a51000" REWARD_FOR_VALIDATOR_SET_CHANGE="1e16" # Parse command line arguments while [[ "$#" -gt 0 ]]; do case $1 in + --network) + NETWORK="$2" + shift + ;; --initConsensusStateBytes) INIT_CONSENSUS_STATE_BYTES="$2" shift @@ -28,4 +33,12 @@ done sed -i -e "s/bytes constant public INIT_CONSENSUS_STATE_BYTES = .*;/bytes constant public INIT_CONSENSUS_STATE_BYTES = hex\"${INIT_CONSENSUS_STATE_BYTES}\";/g" "$OUTPUT" sed -i -e "s/uint256 constant public INIT_REWARD_FOR_VALIDATOR_SER_CHANGE = .*;/uint256 constant public INIT_REWARD_FOR_VALIDATOR_SER_CHANGE = ${REWARD_FOR_VALIDATOR_SET_CHANGE};/g" "$OUTPUT" +case $NETWORK in +local) + sed -i -e "s/alreadyInit = true;/ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(payable(address(this)), 0);\n\t\talreadyInit = true;/g" "$OUTPUT" # just to init SystemReward + ;; +*) + ;; +esac + echo "TendermintLightClient file updated." diff --git a/scripts/generate.sh b/scripts/generate.sh index 3c764771..01076ad3 100644 --- a/scripts/generate.sh +++ b/scripts/generate.sh @@ -9,7 +9,7 @@ function generate_local() { bash ${basedir}/generate-system.sh --bscChainId 02ca bash ${basedir}/generate-crosschain.sh --bscChainId 02ca bash ${basedir}/generate-relayerHub.sh --network local - bash ${basedir}/generate-tendermintLightClient.sh --initConsensusStateBytes "42696e616e63652d436861696e2d4e696c650000000000000000000000000000000000000000000229eca254b3859bffefaf85f4c95da9fbd26527766b784272789c30ec56b380b6eb96442aaab207bc59978ba3dd477690f5c5872334fc39e627723daa97e441e88ba4515150ec3182bc82593df36f8abb25a619187fcfab7e552b94e64ed2deed000000e8d4a51000" + bash ${basedir}/generate-tendermintLightClient.sh --network local --initConsensusStateBytes "42696e616e63652d436861696e2d4e696c650000000000000000000000000000000000000000000229eca254b3859bffefaf85f4c95da9fbd26527766b784272789c30ec56b380b6eb96442aaab207bc59978ba3dd477690f5c5872334fc39e627723daa97e441e88ba4515150ec3182bc82593df36f8abb25a619187fcfab7e552b94e64ed2deed000000e8d4a51000" bash ${basedir}/generate-validatorSet.sh --initBurnRatio 1000 --network local bash ${basedir}/generate-systemReward.sh --network local bash ${basedir}/generate-slashIndicator.sh --network local From c7512be588325fded7e0a5709e9599d98079a0f0 Mon Sep 17 00:00:00 2001 From: buddho Date: Wed, 6 Dec 2023 17:15:20 +0800 Subject: [PATCH 4/4] add hertzfixBlock in genesis.json (#432) --- genesis-template.json | 1 + genesis.json | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/genesis-template.json b/genesis-template.json index 9e765410..5eaae30e 100644 --- a/genesis-template.json +++ b/genesis-template.json @@ -24,6 +24,7 @@ "berlinBlock": 8, "londonBlock": 8, "hertzBlock": 8, + "hertzfixBlock": 8, "shanghaiTime": 0, "keplerTime": 0, "parlia": { diff --git a/genesis.json b/genesis.json index 48f9562c..5abe34da 100644 --- a/genesis.json +++ b/genesis.json @@ -24,7 +24,9 @@ "berlinBlock": 8, "londonBlock": 8, "hertzBlock": 8, - "fusionBlock": 9, + "hertzfixBlock": 8, + "shanghaiTime": 0, + "keplerTime": 0, "parlia": { "period": 3, "epoch": 200