Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions rocketpool/api/service/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ func getGasPriceFromLatestBlock(c *cli.Command) (*api.GasPriceFromLatestBlockRes
}

return &api.GasPriceFromLatestBlockResponse{
Status: "success",
GasPrice: gasPrice.BaseFee,
Error: "",
APIResponse: api.APIResponse{Status: "success"},
GasPrice: gasPrice.BaseFee,
}, nil

}
Expand Down
53 changes: 53 additions & 0 deletions rocketpool/node/auto-tx-gas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package node

import (
"math/big"

log "github.com/rocket-pool/smartnode/shared/logger"
"github.com/rocket-pool/smartnode/shared/math"
"github.com/rocket-pool/smartnode/shared/services/config"
rpgas "github.com/rocket-pool/smartnode/shared/services/gas"
)

// autoTxGas is the node-task view of the Smartnode auto-tx gas settings.
type autoTxGas struct {
thresholdGwei float64
maxFee *big.Int
maxPriorityFee *big.Int
}

// loadAutoTxGas reads the auto-tx gas threshold, manual max fee, and priority
// fee from cfg. A missing or zero priority fee is replaced with the default
// and logged as a warning. A zero max fee is returned as a nil *big.Int so
// callers can fall back to oracle pricing.
func loadAutoTxGas(cfg *config.RocketPoolConfig, logger *log.ColorLogger) autoTxGas {
thresholdGwei := cfg.Smartnode.AutoTxGasThreshold.Value.(float64)

maxFeeGwei := cfg.Smartnode.ManualMaxFee.Value.(float64)
var maxFee *big.Int
if maxFeeGwei != 0 {
maxFee = math.GweiToWei(maxFeeGwei)
}

priorityFeeGwei := cfg.Smartnode.PriorityFee.Value.(float64)
var maxPriorityFee *big.Int
if priorityFeeGwei == 0 {
logger.Printlnf("WARNING: priority fee was missing or 0, setting a default of %.2f.", rpgas.DefaultPriorityFeeGwei)
maxPriorityFee = math.GweiToWei(rpgas.DefaultPriorityFeeGwei)
} else {
maxPriorityFee = math.GweiToWei(priorityFeeGwei)
}

maxFeeGweiLog := 0.0
if maxFee != nil {
maxFeeGweiLog = math.WeiToGwei(maxFee)
}
logger.Printlnf("Loaded auto-tx gas: threshold=%.4f gwei, maxFee=%.4f gwei (0=oracle), priorityFee=%.4f gwei",
thresholdGwei, maxFeeGweiLog, math.WeiToGwei(maxPriorityFee))

return autoTxGas{
thresholdGwei: thresholdGwei,
maxFee: maxFee,
maxPriorityFee: maxPriorityFee,
}
}
52 changes: 52 additions & 0 deletions rocketpool/node/auto-tx-gas_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package node

import (
"testing"

log "github.com/rocket-pool/smartnode/shared/logger"
"github.com/rocket-pool/smartnode/shared/math"
"github.com/rocket-pool/smartnode/shared/services/config"
rpgas "github.com/rocket-pool/smartnode/shared/services/gas"
)

func TestLoadAutoTxGas(t *testing.T) {
cfg := &config.RocketPoolConfig{Smartnode: &config.SmartnodeConfig{}}
cfg.Smartnode.AutoTxGasThreshold.ID = "autoTx"
cfg.Smartnode.AutoTxGasThreshold.Value = 12.5
cfg.Smartnode.ManualMaxFee.ID = "maxFee"
cfg.Smartnode.ManualMaxFee.Value = 30.0
cfg.Smartnode.PriorityFee.ID = "prio"
cfg.Smartnode.PriorityFee.Value = 1.5

logger := log.NewColorLogger(0)
gas := loadAutoTxGas(cfg, &logger)
if gas.thresholdGwei != 12.5 {
t.Fatalf("threshold = %v, want 12.5", gas.thresholdGwei)
}
if gas.maxFee.Cmp(math.GweiToWei(30)) != 0 {
t.Fatalf("maxFee = %s, want 30 gwei", gas.maxFee)
}
if gas.maxPriorityFee.Cmp(math.GweiToWei(1.5)) != 0 {
t.Fatalf("maxPriorityFee = %s, want 1.5 gwei", gas.maxPriorityFee)
}
}

func TestLoadAutoTxGasDefaults(t *testing.T) {
cfg := &config.RocketPoolConfig{Smartnode: &config.SmartnodeConfig{}}
cfg.Smartnode.AutoTxGasThreshold.Value = 0.0
cfg.Smartnode.ManualMaxFee.Value = 0.0
cfg.Smartnode.PriorityFee.Value = 0.0

logger := log.NewColorLogger(0)
gas := loadAutoTxGas(cfg, &logger)
if gas.thresholdGwei != 0 {
t.Fatalf("threshold = %v, want 0", gas.thresholdGwei)
}
if gas.maxFee != nil {
t.Fatalf("maxFee = %s, want nil", gas.maxFee)
}
wantPrio := math.GweiToWei(rpgas.DefaultPriorityFeeGwei)
if gas.maxPriorityFee.Cmp(wantPrio) != 0 {
t.Fatalf("maxPriorityFee = %s, want default %s", gas.maxPriorityFee, wantPrio)
}
}
28 changes: 4 additions & 24 deletions rocketpool/node/defend-challenge-exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/rocket-pool/smartnode/bindings/types"

log "github.com/rocket-pool/smartnode/shared/logger"
"github.com/rocket-pool/smartnode/shared/math"
"github.com/rocket-pool/smartnode/shared/services"
"github.com/rocket-pool/smartnode/shared/services/beacon"
"github.com/rocket-pool/smartnode/shared/services/config"
Expand Down Expand Up @@ -64,26 +63,7 @@ func newDefendChallengeExit(c *cli.Command, logger log.ColorLogger) (*defendChal
return nil, err
}

gasThreshold := cfg.Smartnode.AutoTxGasThreshold.Value.(float64)

// Get the user-requested max fee
maxFeeGwei := cfg.Smartnode.ManualMaxFee.Value.(float64)
var maxFee *big.Int
if maxFeeGwei == 0 {
maxFee = nil
} else {
maxFee = math.GweiToWei(maxFeeGwei)
}

// Get the user-requested max fee
priorityFeeGwei := cfg.Smartnode.PriorityFee.Value.(float64)
var priorityFee *big.Int
if priorityFeeGwei == 0 {
logger.Printlnf("WARNING: priority fee was missing or 0, setting a default of %.2f.", rpgas.DefaultPriorityFeeGwei)
priorityFee = math.GweiToWei(rpgas.DefaultPriorityFeeGwei)
} else {
priorityFee = math.GweiToWei(priorityFeeGwei)
}
gas := loadAutoTxGas(cfg, &logger)

// Return task
return &defendChallengeExit{
Expand All @@ -94,9 +74,9 @@ func newDefendChallengeExit(c *cli.Command, logger log.ColorLogger) (*defendChal
rp: rp,
bc: bc,
d: d,
gasThreshold: gasThreshold,
maxFee: maxFee,
maxPriorityFee: priorityFee,
gasThreshold: gas.thresholdGwei,
maxFee: gas.maxFee,
maxPriorityFee: gas.maxPriorityFee,
gasLimit: 0,
}, nil

Expand Down
28 changes: 4 additions & 24 deletions rocketpool/node/defend-pdao-props.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/rocket-pool/smartnode/bindings/transactions"
"github.com/rocket-pool/smartnode/bindings/types"
log "github.com/rocket-pool/smartnode/shared/logger"
"github.com/rocket-pool/smartnode/shared/math"
"github.com/rocket-pool/smartnode/shared/services"
"github.com/rocket-pool/smartnode/shared/services/beacon"
"github.com/rocket-pool/smartnode/shared/services/config"
Expand Down Expand Up @@ -68,26 +67,7 @@ func newDefendPdaoProps(c *cli.Command, logger log.ColorLogger) (*defendPdaoProp
return nil, err
}

gasThreshold := cfg.Smartnode.AutoTxGasThreshold.Value.(float64)

// Get the user-requested max fee
maxFeeGwei := cfg.Smartnode.ManualMaxFee.Value.(float64)
var maxFee *big.Int
if maxFeeGwei == 0 {
maxFee = nil
} else {
maxFee = math.GweiToWei(maxFeeGwei)
}

// Get the user-requested priority fee
priorityFeeGwei := cfg.Smartnode.PriorityFee.Value.(float64)
var priorityFee *big.Int
if priorityFeeGwei == 0 {
logger.Printlnf("WARNING: priority fee was missing or 0, setting a default of %.2f.", rpgas.DefaultPriorityFeeGwei)
priorityFee = math.GweiToWei(rpgas.DefaultPriorityFeeGwei)
} else {
priorityFee = math.GweiToWei(priorityFeeGwei)
}
gas := loadAutoTxGas(cfg, &logger)

// Get the event interval size
intervalSize := big.NewInt(int64(cfg.Geth.EventLogInterval))
Expand All @@ -112,9 +92,9 @@ func newDefendPdaoProps(c *cli.Command, logger log.ColorLogger) (*defendPdaoProp
w: w,
rp: rp,
bc: bc,
gasThreshold: gasThreshold,
maxFee: maxFee,
maxPriorityFee: priorityFee,
gasThreshold: gas.thresholdGwei,
maxFee: gas.maxFee,
maxPriorityFee: gas.maxPriorityFee,
gasLimit: 0,
nodeAddress: account.Address,
propMgr: propMgr,
Expand Down
45 changes: 11 additions & 34 deletions rocketpool/node/distribute-minipools.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,41 +69,18 @@ func newDistributeMinipools(c *cli.Command, logger log.ColorLogger) (*distribute
return nil, err
}

// Check if auto-distributing is disabled
gasThreshold := cfg.Smartnode.AutoTxGasThreshold.Value.(float64)
gas := loadAutoTxGas(cfg, &logger)
distributeThreshold := cfg.Smartnode.DistributeThreshold.Value.(float64)
disabled := false
if gasThreshold == 0 {
if gas.thresholdGwei == 0 {
logger.Println("Automatic tx gas threshold is 0, disabling auto-distribute.")
disabled = true
} else {
// Safety clamp
if distributeThreshold >= 8 {
logger.Printlnf("WARNING: Auto-distribute threshold is more than 8 ETH (%.6f ETH), reducing to 7.5 ETH for safety", distributeThreshold)
distributeThreshold = 7.5
} else if distributeThreshold == 0 {
logger.Println("Auto-distribute threshold is 0, disabling auto-distribute.")
disabled = true
}
}

// Get the user-requested max fee
maxFeeGwei := cfg.Smartnode.ManualMaxFee.Value.(float64)
var maxFee *big.Int
if maxFeeGwei == 0 {
maxFee = nil
} else {
maxFee = math.GweiToWei(maxFeeGwei)
}

// Get the user-requested max fee
priorityFeeGwei := cfg.Smartnode.PriorityFee.Value.(float64)
var priorityFee *big.Int
if priorityFeeGwei == 0 {
logger.Printlnf("WARNING: priority fee was missing or 0, setting a default of %.2f.", rpgas.DefaultPriorityFeeGwei)
priorityFee = math.GweiToWei(rpgas.DefaultPriorityFeeGwei)
} else {
priorityFee = math.GweiToWei(priorityFeeGwei)
} else if distributeThreshold >= 8 {
logger.Printlnf("WARNING: Auto-distribute threshold is more than 8 ETH (%.6f ETH), reducing to 7.5 ETH for safety", distributeThreshold)
distributeThreshold = 7.5
} else if distributeThreshold == 0 {
logger.Println("Auto-distribute threshold is 0, disabling auto-distribute.")
disabled = true
}

// Return task
Expand All @@ -115,12 +92,12 @@ func newDistributeMinipools(c *cli.Command, logger log.ColorLogger) (*distribute
rp: rp,
bc: bc,
d: d,
gasThreshold: gasThreshold,
gasThreshold: gas.thresholdGwei,
distributeThreshold: math.EthToWei(distributeThreshold),
disabled: disabled,
eight: math.EthToWei(8),
maxFee: maxFee,
maxPriorityFee: priorityFee,
maxFee: gas.maxFee,
maxPriorityFee: gas.maxPriorityFee,
gasLimit: 0,
}, nil

Expand Down
28 changes: 4 additions & 24 deletions rocketpool/node/notify-final-balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/rocket-pool/smartnode/bindings/transactions"

log "github.com/rocket-pool/smartnode/shared/logger"
"github.com/rocket-pool/smartnode/shared/math"
"github.com/rocket-pool/smartnode/shared/services"
"github.com/rocket-pool/smartnode/shared/services/beacon"
"github.com/rocket-pool/smartnode/shared/services/config"
Expand Down Expand Up @@ -63,26 +62,7 @@ func newNotifyFinalBalance(c *cli.Command, logger log.ColorLogger) (*notifyFinal
return nil, err
}

gasThreshold := cfg.Smartnode.AutoTxGasThreshold.Value.(float64)

// Get the user-requested max fee
maxFeeGwei := cfg.Smartnode.ManualMaxFee.Value.(float64)
var maxFee *big.Int
if maxFeeGwei == 0 {
maxFee = nil
} else {
maxFee = math.GweiToWei(maxFeeGwei)
}

// Get the user-requested max fee
priorityFeeGwei := cfg.Smartnode.PriorityFee.Value.(float64)
var priorityFee *big.Int
if priorityFeeGwei == 0 {
logger.Printlnf("WARNING: priority fee was missing or 0, setting a default of %.2f.", rpgas.DefaultPriorityFeeGwei)
priorityFee = math.GweiToWei(rpgas.DefaultPriorityFeeGwei)
} else {
priorityFee = math.GweiToWei(priorityFeeGwei)
}
gas := loadAutoTxGas(cfg, &logger)

// Return task
return &notifyFinalBalance{
Expand All @@ -93,9 +73,9 @@ func newNotifyFinalBalance(c *cli.Command, logger log.ColorLogger) (*notifyFinal
rp: rp,
bc: bc,
d: d,
gasThreshold: gasThreshold,
maxFee: maxFee,
maxPriorityFee: priorityFee,
gasThreshold: gas.thresholdGwei,
maxFee: gas.maxFee,
maxPriorityFee: gas.maxPriorityFee,
gasLimit: 0,
}, nil

Expand Down
28 changes: 4 additions & 24 deletions rocketpool/node/notify-validator-exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/rocket-pool/smartnode/bindings/types"

log "github.com/rocket-pool/smartnode/shared/logger"
"github.com/rocket-pool/smartnode/shared/math"
"github.com/rocket-pool/smartnode/shared/services"
"github.com/rocket-pool/smartnode/shared/services/beacon"
"github.com/rocket-pool/smartnode/shared/services/config"
Expand Down Expand Up @@ -67,26 +66,7 @@ func newNotifyValidatorExit(c *cli.Command, logger log.ColorLogger) (*notifyVali
return nil, err
}

gasThreshold := cfg.Smartnode.AutoTxGasThreshold.Value.(float64)

// Get the user-requested max fee
maxFeeGwei := cfg.Smartnode.ManualMaxFee.Value.(float64)
var maxFee *big.Int
if maxFeeGwei == 0 {
maxFee = nil
} else {
maxFee = math.GweiToWei(maxFeeGwei)
}

// Get the user-requested max fee
priorityFeeGwei := cfg.Smartnode.PriorityFee.Value.(float64)
var priorityFee *big.Int
if priorityFeeGwei == 0 {
logger.Printlnf("WARNING: priority fee was missing or 0, setting a default of %.2f.", rpgas.DefaultPriorityFeeGwei)
priorityFee = math.GweiToWei(rpgas.DefaultPriorityFeeGwei)
} else {
priorityFee = math.GweiToWei(priorityFeeGwei)
}
gas := loadAutoTxGas(cfg, &logger)

// Return task
return &notifyValidatorExit{
Expand All @@ -97,9 +77,9 @@ func newNotifyValidatorExit(c *cli.Command, logger log.ColorLogger) (*notifyVali
rp: rp,
bc: bc,
d: d,
gasThreshold: gasThreshold,
maxFee: maxFee,
maxPriorityFee: priorityFee,
gasThreshold: gas.thresholdGwei,
maxFee: gas.maxFee,
maxPriorityFee: gas.maxPriorityFee,
gasLimit: 0,
}, nil

Expand Down
Loading
Loading