Skip to content

Commit 0f22a33

Browse files
authored
Merge pull request #8242 from onflow/jord/machine-account-defaults-fee-increase
Update machine account balance recommendations
2 parents dad9049 + d920f96 commit 0f22a33

File tree

3 files changed

+23
-68
lines changed

3 files changed

+23
-68
lines changed

module/epochs/machine_account.go

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,39 @@ import (
2323
)
2424

2525
var (
26-
// Hard and soft balance limits for collection and consensus nodes.
27-
// We will log a warning once for a soft limit, and will log an error
28-
// in perpetuity for a hard limit.
26+
// Balance limits for collection and consensus nodes.
2927
// Taken from https://www.notion.so/dapperlabs/Machine-Account-f3c293593ea442a39614fcebf705a132
30-
// TODO update these for FLIP74
3128

32-
defaultSoftMinBalanceLN cadence.UFix64
33-
defaultHardMinBalanceLN cadence.UFix64
34-
defaultSoftMinBalanceSN cadence.UFix64
35-
defaultHardMinBalanceSN cadence.UFix64
29+
cdcRecommendedMinBalanceLN cadence.UFix64
30+
cdcRecommendedMinBalanceSN cadence.UFix64
3631
)
3732

3833
const (
39-
recommendedMinBalanceLN = 0.002
40-
recommendedMinBalanceSN = 0.05
34+
// We recommend node operators refill once they reach this threshold
35+
recommendedMinBalanceLN = 0.25
36+
recommendedMinBalanceSN = 2.0
37+
recommendedRefillToBalanceLN = 0.75
38+
recommendedRefillToBalanceSN = 6.0
4139
)
4240

4341
func init() {
4442
var err error
45-
defaultSoftMinBalanceLN, err = cadence.NewUFix64("0.0025")
46-
if err != nil {
47-
panic(fmt.Errorf("could not convert soft min balance for LN: %w", err))
48-
}
49-
defaultHardMinBalanceLN, err = cadence.NewUFix64("0.002")
43+
cdcRecommendedMinBalanceLN, err = cadence.NewUFix64("0.25")
5044
if err != nil {
5145
panic(fmt.Errorf("could not convert hard min balance for LN: %w", err))
5246
}
53-
defaultSoftMinBalanceSN, err = cadence.NewUFix64("0.125")
54-
if err != nil {
55-
panic(fmt.Errorf("could not convert soft min balance for SN: %w", err))
56-
}
57-
defaultHardMinBalanceSN, err = cadence.NewUFix64("0.05")
47+
cdcRecommendedMinBalanceSN, err = cadence.NewUFix64("2.0")
5848
if err != nil {
5949
panic(fmt.Errorf("could not convert hard min balance for SN: %w", err))
6050
}
6151

6252
// sanity checks
63-
if asFloat, err := ufix64Tofloat64(defaultHardMinBalanceLN); err != nil {
53+
if asFloat, err := ufix64Tofloat64(cdcRecommendedMinBalanceLN); err != nil {
6454
panic(err)
6555
} else if asFloat != recommendedMinBalanceLN {
6656
panic(fmt.Errorf("failed sanity check: %f!=%f", asFloat, recommendedMinBalanceLN))
6757
}
68-
if asFloat, err := ufix64Tofloat64(defaultHardMinBalanceSN); err != nil {
58+
if asFloat, err := ufix64Tofloat64(cdcRecommendedMinBalanceSN); err != nil {
6959
panic(err)
7060
} else if asFloat != recommendedMinBalanceSN {
7161
panic(fmt.Errorf("failed sanity check: %f!=%f", asFloat, recommendedMinBalanceSN))
@@ -91,28 +81,22 @@ func checkMachineAccountRetryBackoff() retry.Backoff {
9181

9282
// MachineAccountValidatorConfig defines configuration options for MachineAccountConfigValidator.
9383
type MachineAccountValidatorConfig struct {
94-
SoftMinBalanceLN cadence.UFix64
9584
HardMinBalanceLN cadence.UFix64
96-
SoftMinBalanceSN cadence.UFix64
9785
HardMinBalanceSN cadence.UFix64
9886
}
9987

10088
func DefaultMachineAccountValidatorConfig() MachineAccountValidatorConfig {
10189
return MachineAccountValidatorConfig{
102-
SoftMinBalanceLN: defaultSoftMinBalanceLN,
103-
HardMinBalanceLN: defaultHardMinBalanceLN,
104-
SoftMinBalanceSN: defaultSoftMinBalanceSN,
105-
HardMinBalanceSN: defaultHardMinBalanceSN,
90+
HardMinBalanceLN: cdcRecommendedMinBalanceLN,
91+
HardMinBalanceSN: cdcRecommendedMinBalanceSN,
10692
}
10793
}
10894

10995
// WithoutBalanceChecks sets minimum balances to 0 to effectively disable minimum
11096
// balance checks. This is useful for test networks where transaction fees are
11197
// disabled.
11298
func WithoutBalanceChecks(conf *MachineAccountValidatorConfig) {
113-
conf.SoftMinBalanceLN = 0
11499
conf.HardMinBalanceLN = 0
115-
conf.SoftMinBalanceSN = 0
116100
conf.HardMinBalanceSN = 0
117101
}
118102

@@ -323,17 +307,11 @@ func CheckMachineAccountInfo(
323307
switch role {
324308
case flow.RoleCollection:
325309
if balance < conf.HardMinBalanceLN {
326-
return fmt.Errorf("machine account balance is below hard minimum (%s < %s)", balance, conf.HardMinBalanceLN)
327-
}
328-
if balance < conf.SoftMinBalanceLN {
329-
log.Warn().Msgf("machine account balance is below recommended balance (%s < %s)", balance, conf.SoftMinBalanceLN)
310+
return fmt.Errorf("machine account balance is below minimum (%s < %s). Please refill to %f FLOW", balance, conf.HardMinBalanceLN, recommendedRefillToBalanceLN)
330311
}
331312
case flow.RoleConsensus:
332313
if balance < conf.HardMinBalanceSN {
333-
return fmt.Errorf("machine account balance is below hard minimum (%s < %s)", balance, conf.HardMinBalanceSN)
334-
}
335-
if balance < conf.SoftMinBalanceSN {
336-
log.Warn().Msgf("machine account balance is below recommended balance (%s < %s)", balance, conf.SoftMinBalanceSN)
314+
return fmt.Errorf("machine account balance is below minimum (%s < %s). Please refill to %f FLOW", balance, conf.HardMinBalanceSN, recommendedRefillToBalanceSN)
337315
}
338316
default:
339317
// sanity check - should be caught earlier in this function

module/epochs/machine_account_test.go

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ func TestMachineAccountChecking(t *testing.T) {
8282
t.Run("account with < hard minimum balance", func(t *testing.T) {
8383
t.Run("collection", func(t *testing.T) {
8484
local, remote := unittest.MachineAccountFixture(t)
85-
remote.Balance = uint64(defaultHardMinBalanceLN) - 1
85+
remote.Balance = uint64(cdcRecommendedMinBalanceLN) - 1
8686
err := CheckMachineAccountInfo(zerolog.Nop(), conf, flow.RoleCollection, local, remote)
8787
require.Error(t, err)
8888
})
8989
t.Run("consensus", func(t *testing.T) {
9090
local, remote := unittest.MachineAccountFixture(t)
91-
remote.Balance = uint64(defaultHardMinBalanceSN) - 1
91+
remote.Balance = uint64(cdcRecommendedMinBalanceSN) - 1
9292
err := CheckMachineAccountInfo(zerolog.Nop(), conf, flow.RoleConsensus, local, remote)
9393
require.Error(t, err)
9494
})
@@ -115,29 +115,6 @@ func TestMachineAccountChecking(t *testing.T) {
115115
})
116116
})
117117

118-
// should log a warning when balance below soft minimum balance (but not
119-
// below hard minimum balance)
120-
t.Run("account with < soft minimum balance", func(t *testing.T) {
121-
t.Run("collection", func(t *testing.T) {
122-
local, remote := unittest.MachineAccountFixture(t)
123-
remote.Balance = uint64(defaultSoftMinBalanceLN) - 1
124-
log, hook := unittest.HookedLogger()
125-
126-
err := CheckMachineAccountInfo(log, conf, flow.RoleCollection, local, remote)
127-
assert.NoError(t, err)
128-
assert.Regexp(t, "machine account balance is below recommended balance", hook.Logs())
129-
})
130-
t.Run("consensus", func(t *testing.T) {
131-
local, remote := unittest.MachineAccountFixture(t)
132-
remote.Balance = uint64(defaultSoftMinBalanceSN) - 1
133-
log, hook := unittest.HookedLogger()
134-
135-
err := CheckMachineAccountInfo(log, conf, flow.RoleConsensus, local, remote)
136-
assert.NoError(t, err)
137-
assert.Regexp(t, "machine account balance is below recommended balance", hook.Logs())
138-
})
139-
})
140-
141118
// should log a warning when the local file deviates from defaults
142119
t.Run("local file deviates from defaults", func(t *testing.T) {
143120
t.Run("hash algo", func(t *testing.T) {
@@ -187,8 +164,8 @@ func TestMachineAccountValidatorBackoff_Overflow(t *testing.T) {
187164
backoff := checkMachineAccountRetryBackoff()
188165

189166
// once the backoff reaches the maximum, it should remain in [(1-jitter)*max,(1+jitter*max)]
190-
max := checkMachineAccountRetryMax + checkMachineAccountRetryMax*(checkMachineAccountRetryJitterPct+1)/100
191-
min := checkMachineAccountRetryMax - checkMachineAccountRetryMax*(checkMachineAccountRetryJitterPct+1)/100
167+
maxBackoff := checkMachineAccountRetryMax + checkMachineAccountRetryMax*(checkMachineAccountRetryJitterPct+1)/100
168+
minBackoff := checkMachineAccountRetryMax - checkMachineAccountRetryMax*(checkMachineAccountRetryJitterPct+1)/100
192169

193170
lastWait, stop := backoff.Next()
194171
assert.False(t, stop)
@@ -199,8 +176,8 @@ func TestMachineAccountValidatorBackoff_Overflow(t *testing.T) {
199176
// * strictly increase, or
200177
// * be within range of max duration + jitter
201178
if wait < lastWait {
202-
assert.Less(t, min, wait)
203-
assert.Less(t, wait, max)
179+
assert.Less(t, minBackoff, wait)
180+
assert.Less(t, wait, maxBackoff)
204181
}
205182
lastWait = wait
206183
}

utils/unittest/fixtures.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2642,7 +2642,7 @@ func MachineAccountFixture(t *testing.T) (
26422642
) {
26432643
info := NodeMachineAccountInfoFixture()
26442644

2645-
bal, err := cadence.NewUFix64("0.5")
2645+
bal, err := cadence.NewUFix64("5.0")
26462646
require.NoError(t, err)
26472647

26482648
acct := &sdk.Account{

0 commit comments

Comments
 (0)