From 8b50ae620bf3873e4bf16426a8f5a4586fc412b6 Mon Sep 17 00:00:00 2001 From: Calin Martinconi Date: Fri, 11 Oct 2024 10:38:26 +0300 Subject: [PATCH] feat: provide reserve capacity height to the staking contract (#4857) --- .github/workflows/beekeeper.yml | 2 +- go.mod | 2 +- go.sum | 4 +- pkg/node/node.go | 2 +- pkg/storageincentives/staking/contract.go | 5 +- .../staking/contract_test.go | 48 ++++++++++++++++--- 6 files changed, 51 insertions(+), 12 deletions(-) diff --git a/.github/workflows/beekeeper.yml b/.github/workflows/beekeeper.yml index 4d2e890ce89..6b56f48e515 100644 --- a/.github/workflows/beekeeper.yml +++ b/.github/workflows/beekeeper.yml @@ -12,7 +12,7 @@ env: REPLICA: 3 RUN_TYPE: "PR RUN" SETUP_CONTRACT_IMAGE: "ethersphere/bee-localchain" - SETUP_CONTRACT_IMAGE_TAG: "0.9.1" + SETUP_CONTRACT_IMAGE_TAG: "0.9.2-rc1" BEELOCAL_BRANCH: "main" BEEKEEPER_BRANCH: "master" BEEKEEPER_METRICS_ENABLED: false diff --git a/go.mod b/go.mod index d8f8b189d37..f37fc36bebc 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/coreos/go-semver v0.3.0 github.com/ethereum/go-ethereum v1.14.3 github.com/ethersphere/go-price-oracle-abi v0.2.0 - github.com/ethersphere/go-storage-incentives-abi v0.9.1 + github.com/ethersphere/go-storage-incentives-abi v0.9.2-rc1 github.com/ethersphere/go-sw3-abi v0.6.5 github.com/ethersphere/langos v1.0.0 github.com/go-playground/validator/v10 v10.11.1 diff --git a/go.sum b/go.sum index 5f07945ff40..b837278926d 100644 --- a/go.sum +++ b/go.sum @@ -236,8 +236,8 @@ github.com/ethereum/go-ethereum v1.14.3 h1:5zvnAqLtnCZrU9uod1JCvHWJbPMURzYFHfc2e github.com/ethereum/go-ethereum v1.14.3/go.mod h1:1STrq471D0BQbCX9He0hUj4bHxX2k6mt5nOQJhDNOJ8= github.com/ethersphere/go-price-oracle-abi v0.2.0 h1:wtIcYLgNZHY4BjYwJCnu93SvJdVAZVvBaKinspyyHvQ= github.com/ethersphere/go-price-oracle-abi v0.2.0/go.mod h1:sI/Qj4/zJ23/b1enzwMMv0/hLTpPNVNacEwCWjo6yBk= -github.com/ethersphere/go-storage-incentives-abi v0.9.1 h1:/FGh5Bn78hlxMu0YjSFf1APzmmrCmmThDOZMWY+G2Cs= -github.com/ethersphere/go-storage-incentives-abi v0.9.1/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc= +github.com/ethersphere/go-storage-incentives-abi v0.9.2-rc1 h1:Cf3LFlz87FqlTqcuN4q4Hry4iUaAbbroaFxpCgHVhtY= +github.com/ethersphere/go-storage-incentives-abi v0.9.2-rc1/go.mod h1:SXvJVtM4sEsaSKD0jc1ClpDLw8ErPoROZDme4Wrc/Nc= github.com/ethersphere/go-sw3-abi v0.6.5 h1:M5dcIe1zQYvGpY2K07UNkNU9Obc4U+A1fz68Ho/Q+XE= github.com/ethersphere/go-sw3-abi v0.6.5/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU= github.com/ethersphere/langos v1.0.0 h1:NBtNKzXTTRSue95uOlzPN4py7Aofs0xWPzyj4AI1Vcc= diff --git a/pkg/node/node.go b/pkg/node/node.go index b42e53737cd..486e76e324f 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -1002,7 +1002,7 @@ func NewBee( stakingContractAddress = common.HexToAddress(o.StakingContractAddress) } - stakingContract := staking.New(overlayEthAddress, stakingContractAddress, abiutil.MustParseABI(chainCfg.StakingABI), bzzTokenAddress, transactionService, common.BytesToHash(nonce), o.TrxDebugMode) + stakingContract := staking.New(overlayEthAddress, stakingContractAddress, abiutil.MustParseABI(chainCfg.StakingABI), bzzTokenAddress, transactionService, common.BytesToHash(nonce), o.TrxDebugMode, uint8(o.ReserveCapacityDoubling)) if chainEnabled && changedOverlay { stake, err := stakingContract.GetPotentialStake(ctx) diff --git a/pkg/storageincentives/staking/contract.go b/pkg/storageincentives/staking/contract.go index 966efaee8c5..365153f5917 100644 --- a/pkg/storageincentives/staking/contract.go +++ b/pkg/storageincentives/staking/contract.go @@ -59,6 +59,7 @@ type contract struct { transactionService transaction.Service overlayNonce common.Hash gasLimit uint64 + height uint8 } func New( @@ -69,6 +70,7 @@ func New( transactionService transaction.Service, nonce common.Hash, setGasLimit bool, + height uint8, ) Contract { var gasLimit uint64 @@ -84,6 +86,7 @@ func New( transactionService: transactionService, overlayNonce: nonce, gasLimit: gasLimit, + height: height, } } @@ -293,7 +296,7 @@ func (c *contract) sendTransaction(ctx context.Context, callData []byte, desc st } func (c *contract) sendDepositStakeTransaction(ctx context.Context, stakedAmount *big.Int, nonce common.Hash) (*types.Receipt, error) { - callData, err := c.stakingContractABI.Pack("manageStake", nonce, stakedAmount) + callData, err := c.stakingContractABI.Pack("manageStake", nonce, stakedAmount, c.height) if err != nil { return nil, err } diff --git a/pkg/storageincentives/staking/contract_test.go b/pkg/storageincentives/staking/contract_test.go index 4fa0a36ff4e..15cb84b0882 100644 --- a/pkg/storageincentives/staking/contract_test.go +++ b/pkg/storageincentives/staking/contract_test.go @@ -25,6 +25,8 @@ import ( var stakingContractABI = abiutil.MustParseABI(chaincfg.Testnet.StakingABI) +const stakingHeight = uint8(0) + func TestIsOverlayFrozen(t *testing.T) { t.Parallel() @@ -55,6 +57,7 @@ func TestIsOverlayFrozen(t *testing.T) { ), nonce, false, + stakingHeight, ) frozen, err := contract.IsOverlayFrozen(ctx, uint64(height-1)) @@ -95,7 +98,7 @@ func TestDepositStake(t *testing.T) { totalAmount := big.NewInt(100000000000000000) prevStake := big.NewInt(0) - expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, stakedAmount) + expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, stakedAmount, stakingHeight) if err != nil { t.Fatal(err) } @@ -143,6 +146,7 @@ func TestDepositStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -156,7 +160,7 @@ func TestDepositStake(t *testing.T) { totalAmount := big.NewInt(100000000000000000) prevStake := big.NewInt(2) - expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, big.NewInt(100000000000000000)) + expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, big.NewInt(100000000000000000), stakingHeight) if err != nil { t.Fatal(err) } @@ -204,6 +208,7 @@ func TestDepositStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -243,6 +248,7 @@ func TestDepositStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err := contract.DepositStake(ctx, big.NewInt(0)) @@ -275,6 +281,7 @@ func TestDepositStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err := contract.DepositStake(ctx, big.NewInt(100000000000000000)) @@ -307,6 +314,7 @@ func TestDepositStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err := contract.DepositStake(ctx, big.NewInt(100000000000000000)) @@ -345,6 +353,7 @@ func TestDepositStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err := contract.DepositStake(ctx, stakedAmount) @@ -394,6 +403,7 @@ func TestDepositStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -456,6 +466,7 @@ func TestDepositStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -516,6 +527,7 @@ func TestDepositStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.DepositStake(ctx, stakedAmount) @@ -542,6 +554,7 @@ func TestDepositStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err := contract.DepositStake(ctx, stakedAmount) @@ -566,7 +579,7 @@ func TestChangeStakeOverlay(t *testing.T) { t.Run("ok", func(t *testing.T) { t.Parallel() - expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, stakedAmount) + expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, stakedAmount, stakingHeight) if err != nil { t.Fatal(err) } @@ -597,6 +610,7 @@ func TestChangeStakeOverlay(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.ChangeStakeOverlay(ctx, nonce) @@ -623,6 +637,7 @@ func TestChangeStakeOverlay(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err := contract.ChangeStakeOverlay(ctx, nonce) @@ -634,7 +649,7 @@ func TestChangeStakeOverlay(t *testing.T) { t.Run("invalid call data", func(t *testing.T) { t.Parallel() - expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, stakedAmount) + expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, stakedAmount, stakingHeight) if err != nil { t.Fatal(err) } @@ -657,6 +672,7 @@ func TestChangeStakeOverlay(t *testing.T) { ), nonce, false, + stakingHeight, ) newNonce := make([]byte, 32) @@ -671,7 +687,7 @@ func TestChangeStakeOverlay(t *testing.T) { t.Run("transaction reverted", func(t *testing.T) { t.Parallel() - expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, stakedAmount) + expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, stakedAmount, stakingHeight) if err != nil { t.Fatal(err) } @@ -702,6 +718,7 @@ func TestChangeStakeOverlay(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.ChangeStakeOverlay(ctx, nonce) @@ -713,7 +730,7 @@ func TestChangeStakeOverlay(t *testing.T) { t.Run("transaction error", func(t *testing.T) { t.Parallel() - expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, stakedAmount) + expectedCallData, err := stakingContractABI.Pack("manageStake", nonce, stakedAmount, stakingHeight) if err != nil { t.Fatal(err) } @@ -742,6 +759,7 @@ func TestChangeStakeOverlay(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.ChangeStakeOverlay(ctx, nonce) @@ -788,6 +806,7 @@ func TestGetCommittedStake(t *testing.T) { ), nonce, false, + stakingHeight, ) stakedAmount, err := contract.GetPotentialStake(ctx) @@ -825,6 +844,7 @@ func TestGetCommittedStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.GetPotentialStake(ctx) @@ -862,6 +882,7 @@ func TestGetCommittedStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.GetPotentialStake(ctx) @@ -885,6 +906,7 @@ func TestGetCommittedStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err := contract.GetPotentialStake(ctx) @@ -931,6 +953,7 @@ func TestGetWithdrawableStake(t *testing.T) { ), nonce, false, + stakingHeight, ) withdrawableStake, err := contract.GetWithdrawableStake(ctx) @@ -968,6 +991,7 @@ func TestGetWithdrawableStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.GetPotentialStake(ctx) @@ -991,6 +1015,7 @@ func TestGetWithdrawableStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err := contract.GetPotentialStake(ctx) @@ -1057,6 +1082,7 @@ func TestWithdrawStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.WithdrawStake(ctx) @@ -1092,6 +1118,7 @@ func TestWithdrawStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.WithdrawStake(ctx) @@ -1149,6 +1176,7 @@ func TestWithdrawStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.WithdrawStake(ctx) @@ -1204,6 +1232,7 @@ func TestWithdrawStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.WithdrawStake(ctx) @@ -1237,6 +1266,7 @@ func TestWithdrawStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.WithdrawStake(ctx) @@ -1312,6 +1342,7 @@ func TestMigrateStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.MigrateStake(ctx) @@ -1346,6 +1377,7 @@ func TestMigrateStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.MigrateStake(ctx) @@ -1426,6 +1458,7 @@ func TestMigrateStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.MigrateStake(ctx) @@ -1490,6 +1523,7 @@ func TestMigrateStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.MigrateStake(ctx) @@ -1524,6 +1558,7 @@ func TestMigrateStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.WithdrawStake(ctx) @@ -1566,6 +1601,7 @@ func TestMigrateStake(t *testing.T) { ), nonce, false, + stakingHeight, ) _, err = contract.MigrateStake(ctx)