From 36ca94221c5403ff1ad9cb713c708941ff7a2fef Mon Sep 17 00:00:00 2001 From: Yang Hau Date: Thu, 22 Jun 2023 11:34:56 -0500 Subject: [PATCH] wip --- packages/origin/origin.go | 2 +- packages/solo/solo.go | 2 +- .../governance/governanceimpl/chainowner.go | 6 +++--- .../vm/core/governance/governanceimpl/impl.go | 4 ++-- packages/vm/core/governance/interface.go | 8 ++++---- packages/vm/core/governance/internal.go | 4 ++-- packages/vm/core/testcore/accounts_test.go | 2 +- packages/vm/core/testcore/base_test.go | 18 +++++++++--------- packages/vm/core/testcore/governance_test.go | 2 +- .../vm/vmcontext/vmtxbuilder/txbuilder_test.go | 2 +- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/origin/origin.go b/packages/origin/origin.go index 2797d11f54..a053828723 100644 --- a/packages/origin/origin.go +++ b/packages/origin/origin.go @@ -170,7 +170,7 @@ func NewChainOriginTransaction( } minSD := parameters.L1().Protocol.RentStructure.MinRent(aliasOutput) - minAmount := minSD + governance.DefaultMinCommonAccountBalance + minAmount := minSD + governance.DefaultMinBaseTokensOnCommonAccount if aliasOutput.Amount < minAmount { aliasOutput.Amount = minAmount } diff --git a/packages/solo/solo.go b/packages/solo/solo.go index 3881baac60..903d301fdb 100644 --- a/packages/solo/solo.go +++ b/packages/solo/solo.go @@ -280,7 +280,7 @@ func (env *Solo) NewChainExt( chainOriginator, stateControllerAddr, stateControllerAddr, - initBaseTokens, // will be adjusted to min storage deposit + MinimumBaseTokensOnCommonAccount + initBaseTokens, // will be adjusted to min storage deposit + DefaultMinBaseTokensOnCommonAccount initParams, outs, outIDs, diff --git a/packages/vm/core/governance/governanceimpl/chainowner.go b/packages/vm/core/governance/governanceimpl/chainowner.go index 6b71437a17..6016fdabe5 100644 --- a/packages/vm/core/governance/governanceimpl/chainowner.go +++ b/packages/vm/core/governance/governanceimpl/chainowner.go @@ -68,15 +68,15 @@ func getPayoutAgentID(ctx isc.SandboxView) dict.Dict { func setMinCommonAccountBalance(ctx isc.Sandbox) dict.Dict { ctx.RequireCallerIsChainOwner() minCommonAccountBalance := ctx.Params().MustGetUint64(governance.ParamSetMinCommonAccountBalance) - ctx.State().Set(governance.StateVarMinCommonAccountBalance, codec.EncodeUint64(minCommonAccountBalance)) + ctx.State().Set(governance.StateVarMinBaseTokensOnCommonAccount, codec.EncodeUint64(minCommonAccountBalance)) return nil } func getMinCommonAccountBalance(ctx isc.SandboxView) dict.Dict { ret := dict.New() - minCommonAccountBalance := ctx.StateR().Get(governance.StateVarMinCommonAccountBalance) + minCommonAccountBalance := ctx.StateR().Get(governance.StateVarMinBaseTokensOnCommonAccount) if minCommonAccountBalance == nil { - minCommonAccountBalance = codec.EncodeUint64(governance.DefaultMinCommonAccountBalance) + minCommonAccountBalance = codec.EncodeUint64(governance.DefaultMinBaseTokensOnCommonAccount) } ret.Set(governance.ParamSetMinCommonAccountBalance, minCommonAccountBalance) return ret diff --git a/packages/vm/core/governance/governanceimpl/impl.go b/packages/vm/core/governance/governanceimpl/impl.go index 61cdc48c0f..6434b3b911 100644 --- a/packages/vm/core/governance/governanceimpl/impl.go +++ b/packages/vm/core/governance/governanceimpl/impl.go @@ -60,6 +60,6 @@ func SetInitialState(state kv.KVStore, chainOwner isc.AgentID, blockKeepAmount i state.Set(governance.VarGasLimitsBytes, gas.LimitsDefault.Bytes()) state.Set(governance.VarMaintenanceStatus, codec.Encode(false)) state.Set(governance.VarBlockKeepAmount, codec.EncodeInt32(blockKeepAmount)) - // FIXME we should use MinimumBaseTokensOnCommonAccount instead. - // state.Set(governance.StateVarMinCommonAccountBalance, codec.EncodeUint64(governance.DefaultMinCommonAccountBalance)) + // FIXME we should use DefaultMinBaseTokensOnCommonAccount instead. + state.Set(governance.StateVarMinBaseTokensOnCommonAccount, codec.EncodeUint64(governance.DefaultMinBaseTokensOnCommonAccount)) } diff --git a/packages/vm/core/governance/interface.go b/packages/vm/core/governance/interface.go index dcc167e211..23cc43d96f 100644 --- a/packages/vm/core/governance/interface.go +++ b/packages/vm/core/governance/interface.go @@ -58,15 +58,15 @@ var ( // state variables const ( - // DefaultMinCommonAccountBalance can't harvest the minimum - DefaultMinCommonAccountBalance = uint64(3000) + // DefaultMinBaseTokensOnCommonAccount can't harvest the minimum + DefaultMinBaseTokensOnCommonAccount = uint64(3000) // state controller StateVarAllowedStateControllerAddresses = "a" StateVarRotateToAddress = "r" - StateVarPayoutAgentID = "pa" - StateVarMinCommonAccountBalance = "vs" + StateVarPayoutAgentID = "pa" + StateVarMinBaseTokensOnCommonAccount = "vs" // chain owner VarChainOwnerID = "o" diff --git a/packages/vm/core/governance/internal.go b/packages/vm/core/governance/internal.go index c3d167ee10..2d9f05f79b 100644 --- a/packages/vm/core/governance/internal.go +++ b/packages/vm/core/governance/internal.go @@ -69,9 +69,9 @@ func MustGetChainInfo(state kv.KVStoreReader, chainID isc.ChainID) *isc.ChainInf func MustGetMinCommonAccountBalance(state kv.KVStoreReader) uint64 { d := kvdecoder.New(state) - minCommonAccountBalance, err := d.GetUint64(StateVarMinCommonAccountBalance) + minCommonAccountBalance, err := d.GetUint64(StateVarMinBaseTokensOnCommonAccount) if err != nil { - // FIXME we should use DefaultMinCommonAccountBalance instead. + // FIXME we should use DefaultMinBaseTokensOnCommonAccount instead. return 0 } return minCommonAccountBalance diff --git a/packages/vm/core/testcore/accounts_test.go b/packages/vm/core/testcore/accounts_test.go index a253515a4b..7ba5097a08 100644 --- a/packages/vm/core/testcore/accounts_test.go +++ b/packages/vm/core/testcore/accounts_test.go @@ -819,7 +819,7 @@ func TestTransferAndCheckNativeTokens(t *testing.T) { commonAssets = v.ch.L2CommonAccountAssets() // in the common account should have left minimum plus gas fee from the last request - require.EqualValues(t, governance.DefaultMinCommonAccountBalance, commonAssets.BaseTokens) + require.EqualValues(t, governance.DefaultMinBaseTokensOnCommonAccount, commonAssets.BaseTokens) require.EqualValues(t, 0, len(commonAssets.NativeTokens)) } diff --git a/packages/vm/core/testcore/base_test.go b/packages/vm/core/testcore/base_test.go index 6177bce511..4d85c2d2ee 100644 --- a/packages/vm/core/testcore/base_test.go +++ b/packages/vm/core/testcore/base_test.go @@ -46,7 +46,7 @@ func TestInitLoad(t *testing.T) { require.EqualValues(t, 0, len(cassets.NativeTokens)) t.Logf("common base tokens: %d", ch.L2CommonAccountBaseTokens()) - require.True(t, cassets.BaseTokens >= accounts.MinimumBaseTokensOnCommonAccount) + require.True(t, cassets.BaseTokens >= governance.DefaultMinBaseTokensOnCommonAccount) env.VerifyDBHash(hashing.MustHashValueFromHex("0x49413f4c5b68285c852f9693904c5bc622c3907eea60307b79fa8db971cc8a62")) } @@ -111,7 +111,7 @@ func TestNoTargetPostOnLedger(t *testing.T) { totalBaseTokensBefore := ch.L2TotalBaseTokens() originatorsL2BaseTokensBefore := ch.L2BaseTokens(ch.OriginatorAgentID) originatorsL1BaseTokensBefore := env.L1BaseTokens(ch.OriginatorAddress) - require.EqualValues(t, governance.DefaultMinCommonAccountBalance, ch.L2CommonAccountBaseTokens()) + require.EqualValues(t, governance.DefaultMinBaseTokensOnCommonAccount, ch.L2CommonAccountBaseTokens()) req := solo.NewCallParams("dummyContract", "dummyEP"). WithGasBudget(100_000) @@ -135,7 +135,7 @@ func TestNoTargetPostOnLedger(t *testing.T) { // originator (user) is charged with gas fee on L2 ch.AssertL2BaseTokens(ch.OriginatorAgentID, originatorsL2BaseTokensBefore+reqStorageDeposit) // all gas fee goes to the common account - require.EqualValues(t, governance.DefaultMinCommonAccountBalance-changeInAOminCommonAccountBalance, commonAccountBaseTokensAfter) + require.EqualValues(t, governance.DefaultMinBaseTokensOnCommonAccount-changeInAOminCommonAccountBalance, commonAccountBaseTokensAfter) }) t.Run("no contract,originator!=user", func(t *testing.T) { env := solo.New(t, &solo.InitOptions{AutoAdjustStorageDeposit: true}) @@ -149,7 +149,7 @@ func TestNoTargetPostOnLedger(t *testing.T) { originatorsL2BaseTokensBefore := ch.L2BaseTokens(ch.OriginatorAgentID) originatorsL1BaseTokensBefore := env.L1BaseTokens(ch.OriginatorAddress) env.AssertL1BaseTokens(senderAddr, utxodb.FundsFromFaucetAmount) - require.EqualValues(t, governance.DefaultMinCommonAccountBalance, ch.L2CommonAccountBaseTokens()) + require.EqualValues(t, governance.DefaultMinBaseTokensOnCommonAccount, ch.L2CommonAccountBaseTokens()) req := solo.NewCallParams("dummyContract", "dummyEP"). WithGasBudget(100_000) @@ -178,7 +178,7 @@ func TestNoTargetPostOnLedger(t *testing.T) { // user is charged with gas fee on L2 ch.AssertL2BaseTokens(senderAgentID, reqStorageDeposit-rec.GasFeeCharged) // all gas fee goes to the common account - require.EqualValues(t, governance.DefaultMinCommonAccountBalance-changeInAOminCommonAccountBalance, commonAccountBaseTokensAfter) + require.EqualValues(t, governance.DefaultMinBaseTokensOnCommonAccount-changeInAOminCommonAccountBalance, commonAccountBaseTokensAfter) }) t.Run("no EP,originator==user", func(t *testing.T) { env := solo.New(t, &solo.InitOptions{AutoAdjustStorageDeposit: true}) @@ -188,7 +188,7 @@ func TestNoTargetPostOnLedger(t *testing.T) { totalBaseTokensBefore := ch.L2TotalBaseTokens() originatorsL2BaseTokensBefore := ch.L2BaseTokens(ch.OriginatorAgentID) originatorsL1BaseTokensBefore := env.L1BaseTokens(ch.OriginatorAddress) - require.EqualValues(t, governance.DefaultMinCommonAccountBalance, ch.L2CommonAccountBaseTokens()) + require.EqualValues(t, governance.DefaultMinBaseTokensOnCommonAccount, ch.L2CommonAccountBaseTokens()) req := solo.NewCallParams(root.Contract.Name, "dummyEP"). WithGasBudget(100_000) @@ -212,7 +212,7 @@ func TestNoTargetPostOnLedger(t *testing.T) { // originator (user) is charged with gas fee on L2 ch.AssertL2BaseTokens(ch.OriginatorAgentID, originatorsL2BaseTokensBefore+reqStorageDeposit) // all gas fee goes to the common account - require.EqualValues(t, governance.DefaultMinCommonAccountBalance-changeInAOminCommonAccountBalance, commonAccountBaseTokensAfter) + require.EqualValues(t, governance.DefaultMinBaseTokensOnCommonAccount-changeInAOminCommonAccountBalance, commonAccountBaseTokensAfter) }) t.Run("no EP,originator!=user", func(t *testing.T) { env := solo.New(t, &solo.InitOptions{AutoAdjustStorageDeposit: true}) @@ -226,7 +226,7 @@ func TestNoTargetPostOnLedger(t *testing.T) { originatorsL2BaseTokensBefore := ch.L2BaseTokens(ch.OriginatorAgentID) originatorsL1BaseTokensBefore := env.L1BaseTokens(ch.OriginatorAddress) env.AssertL1BaseTokens(senderAddr, utxodb.FundsFromFaucetAmount) - require.EqualValues(t, governance.DefaultMinCommonAccountBalance, ch.L2CommonAccountBaseTokens()) + require.EqualValues(t, governance.DefaultMinBaseTokensOnCommonAccount, ch.L2CommonAccountBaseTokens()) req := solo.NewCallParams(root.Contract.Name, "dummyEP"). WithGasBudget(100_000) @@ -255,7 +255,7 @@ func TestNoTargetPostOnLedger(t *testing.T) { ch.AssertL2BaseTokens(senderAgentID, reqStorageDeposit-rec.GasFeeCharged) // all gas fee goes to the common account require.EqualValues(t, - governance.DefaultMinCommonAccountBalance-changeInAOminCommonAccountBalance, + governance.DefaultMinBaseTokensOnCommonAccount-changeInAOminCommonAccountBalance, commonAccountBaseTokensAfter, ) }) diff --git a/packages/vm/core/testcore/governance_test.go b/packages/vm/core/testcore/governance_test.go index a32239b6af..82f486831f 100644 --- a/packages/vm/core/testcore/governance_test.go +++ b/packages/vm/core/testcore/governance_test.go @@ -513,7 +513,7 @@ func TestGovernanceSetGetMinCommonAccountBalance(t *testing.T) { retByte := initRetDict.Get(governance.ParamSetMinCommonAccountBalance) retMinCommonAccountBalance, err := codec.DecodeUint64(retByte) require.NoError(t, err) - require.Equal(t, governance.DefaultMinCommonAccountBalance, retMinCommonAccountBalance) + require.Equal(t, governance.DefaultMinBaseTokensOnCommonAccount, retMinCommonAccountBalance) minCommonAccountBalance := uint64(123456) _, err = ch.PostRequestSync( diff --git a/packages/vm/vmcontext/vmtxbuilder/txbuilder_test.go b/packages/vm/vmcontext/vmtxbuilder/txbuilder_test.go index 22bd322f6a..c53e062c6e 100644 --- a/packages/vm/vmcontext/vmtxbuilder/txbuilder_test.go +++ b/packages/vm/vmcontext/vmtxbuilder/txbuilder_test.go @@ -395,7 +395,7 @@ func TestTxBuilderConsistency(t *testing.T) { } func TestFoundries(t *testing.T) { - const initialTotalBaseTokens = 10*isc.Million + governance.DefaultMinCommonAccountBalance + const initialTotalBaseTokens = 10*isc.Million + governance.DefaultMinBaseTokensOnCommonAccount addr := tpkg.RandEd25519Address() aliasID := testiotago.RandAliasID() anchor := &iotago.AliasOutput{