Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
howjmay committed Jun 22, 2023
1 parent bfe1c0c commit 36ca942
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/origin/origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion packages/solo/solo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/vm/core/governance/governanceimpl/chainowner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/core/governance/governanceimpl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
8 changes: 4 additions & 4 deletions packages/vm/core/governance/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/core/governance/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/core/testcore/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
18 changes: 9 additions & 9 deletions packages/vm/core/testcore/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down Expand Up @@ -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)
Expand All @@ -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})
Expand All @@ -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)
Expand Down Expand Up @@ -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})
Expand All @@ -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)
Expand All @@ -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})
Expand All @@ -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)
Expand Down Expand Up @@ -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,
)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/core/testcore/governance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/vmcontext/vmtxbuilder/txbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 36ca942

Please sign in to comment.