Skip to content

Commit

Permalink
Consolidate fields, handle the priofee > maxfee case in task loop
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspanf committed Oct 1, 2024
1 parent fb0c74e commit 171c72c
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 134 deletions.
25 changes: 13 additions & 12 deletions rocketpool-daemon/node/defend-pdao-props.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ type DefendPdaoProps struct {
rp *rocketpool.RocketPool
bc beacon.IBeaconClient
rs *config.RocketPoolResources
gasThreshold float64
maxFee *big.Int
maxPriorityFee *big.Int
gasSettings *GasSettings
gasLimit uint64
nodeAddress common.Address
propMgr *proposals.ProposalManager
Expand All @@ -56,6 +54,12 @@ func NewDefendPdaoProps(ctx context.Context, sp *services.ServiceProvider, logge
cfg := sp.GetConfig()
log := logger.With(slog.String(keys.TaskKey, "Defend PDAO Proposals"))
maxFee, maxPriorityFee := getAutoTxInfo(cfg, log)
gasSettings := &GasSettings{
maxFee: maxFee,
maxPriorityFee: maxPriorityFee,
gasThreshold: cfg.AutoTxGasThreshold.Value,
}

return &DefendPdaoProps{
ctx: ctx,
sp: sp,
Expand All @@ -65,9 +69,7 @@ func NewDefendPdaoProps(ctx context.Context, sp *services.ServiceProvider, logge
rp: sp.GetRocketPool(),
bc: sp.GetBeaconClient(),
rs: cfg.GetRocketPoolResources(),
gasThreshold: cfg.AutoTxGasThreshold.Value,
maxFee: maxFee,
maxPriorityFee: maxPriorityFee,
gasSettings: gasSettings,
lastScannedBlock: nil,
intervalSize: big.NewInt(int64(config.EventLogInterval)),
}
Expand Down Expand Up @@ -226,21 +228,20 @@ func (t *DefendPdaoProps) defendProposal(prop defendableProposal) error {
}

// Get the max fee
maxFee := t.maxFee
if maxFee == nil || maxFee.Uint64() == 0 {
maxFee, err = gas.GetMaxFeeWeiForDaemon(t.logger)
if t.gasSettings.maxFee == nil || t.gasSettings.maxFee.Uint64() == 0 {
t.gasSettings.maxFee, err = gas.GetMaxFeeWeiForDaemon(t.logger)
if err != nil {
return err
}
}

// Print the gas info
if !gas.PrintAndCheckGasInfo(txInfo.SimulationResult, true, t.gasThreshold, t.logger, maxFee, t.gasLimit) {
if !gas.PrintAndCheckGasInfo(txInfo.SimulationResult, true, t.gasSettings.gasThreshold, t.logger, t.gasSettings.maxFee, t.gasLimit) {
t.logger.Warn("NOTICE: Challenge responses bypass the automatic TX gas threshold, responding for safety.")
}

opts.GasFeeCap = maxFee
opts.GasTipCap = t.maxPriorityFee
// Set GasFeeCap and GasTipCap
t.gasSettings.ApplyTo(opts)
opts.GasLimit = txInfo.SimulationResult.SafeGasLimit

// Print TX info and wait for it to be included in a block
Expand Down
31 changes: 16 additions & 15 deletions rocketpool-daemon/node/distribute-minipools.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,24 @@ type DistributeMinipools struct {
bc beacon.IBeaconClient
d *client.Client
mpMgr *minipool.MinipoolManager
gasThreshold float64
distributeThreshold *big.Int
eight *big.Int
maxFee *big.Int
maxPriorityFee *big.Int
gasSettings *GasSettings
}

// Create distribute minipools task
func NewDistributeMinipools(sp *services.ServiceProvider, logger *log.Logger) *DistributeMinipools {
cfg := sp.GetConfig()
log := logger.With(slog.String(keys.TaskKey, "Distribute Minipools"))
maxFee, maxPriorityFee := getAutoTxInfo(cfg, log)
gasThreshold := cfg.AutoTxGasThreshold.Value

if gasThreshold == 0 {
gasSettings := &GasSettings{
maxFee: maxFee,
maxPriorityFee: maxPriorityFee,
gasThreshold: cfg.AutoTxGasThreshold.Value,
}

if gasSettings.gasThreshold == 0 {
logger.Info("Automatic tx gas threshold is 0, disabling auto-distribute.")
}

Expand All @@ -74,18 +77,16 @@ func NewDistributeMinipools(sp *services.ServiceProvider, logger *log.Logger) *D
rp: sp.GetRocketPool(),
bc: sp.GetBeaconClient(),
d: sp.GetDocker().(*client.Client),
gasThreshold: gasThreshold,
distributeThreshold: distributeThreshold,
maxFee: maxFee,
maxPriorityFee: maxPriorityFee,
gasSettings: gasSettings,
eight: eth.EthToWei(8),
}
}

// Distribute minipools
func (t *DistributeMinipools) Run(state *state.NetworkState) error {
// Check if auto-distributing is disabled
if t.gasThreshold == 0 {
if t.gasSettings.gasThreshold == 0 {
return nil
}

Expand Down Expand Up @@ -201,18 +202,18 @@ func (t *DistributeMinipools) distributeMinipools(submissions []*eth.Transaction
}

// Get the max fee
maxFee := t.maxFee
if maxFee == nil || maxFee.Uint64() == 0 {
maxFee, err = gas.GetMaxFeeWeiForDaemon(t.logger)
if t.gasSettings.maxFee == nil || t.gasSettings.maxFee.Uint64() == 0 {
t.gasSettings.maxFee, err = gas.GetMaxFeeWeiForDaemon(t.logger)
if err != nil {
return err
}
}
opts.GasFeeCap = maxFee
opts.GasTipCap = t.maxPriorityFee

// Set GasFeeCap and GasTipCap
t.gasSettings.ApplyTo(opts)

// Print the gas info
if !gas.PrintAndCheckGasInfoForBatch(submissions, true, t.gasThreshold, t.logger, maxFee) {
if !gas.PrintAndCheckGasInfoForBatch(submissions, true, t.gasSettings.gasThreshold, t.logger, t.gasSettings.maxFee) {
return nil
}

Expand Down
26 changes: 26 additions & 0 deletions rocketpool-daemon/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ type TaskLoop struct {
secondsDelta float64
}

type GasSettings struct {
maxFee *big.Int
maxPriorityFee *big.Int
gasThreshold float64
}

func NewTaskLoop(sp *services.ServiceProvider, wg *sync.WaitGroup) *TaskLoop {
logger := sp.GetTasksLogger()
ctx := logger.CreateContextWithLogger(sp.GetBaseContext())
Expand Down Expand Up @@ -465,3 +471,23 @@ func calculateTotalEffectiveStakeForNetwork(state *state.NetworkState) *big.Int
}
return total
}

// Applies GasFeeCap and GasTipCap to opts and handles a case where the user-inputted maxPriorityFee is greater than the oracle based maxFee
// If so, maxPriorityFee is appplied to opts as the min(maxPriorityFee, 25% of the oracle based maxFee)
func (g *GasSettings) ApplyTo(opts *bind.TransactOpts) *bind.TransactOpts {
opts.GasFeeCap = g.maxFee
// If maxPriorityFee < maxFee, apply maxPriorityFee to opts
if g.maxPriorityFee.Cmp(g.maxFee) < 0 {
opts.GasTipCap = g.maxPriorityFee
return opts
}
quarterMaxFee := new(big.Int).Div(g.maxFee, big.NewInt(4))
// Otherwise apply maxPriorityFee to opts as min(priorityFee, 25% of the oracle based maxFee)
if g.maxPriorityFee.Cmp(quarterMaxFee) < 0 {
opts.GasTipCap = g.maxPriorityFee
} else {
opts.GasTipCap = quarterMaxFee
}
return opts

}
50 changes: 26 additions & 24 deletions rocketpool-daemon/node/promote-minipools.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,35 @@ import (

// Promote minipools task
type PromoteMinipools struct {
sp *services.ServiceProvider
logger *slog.Logger
alerter *alerting.Alerter
cfg *config.SmartNodeConfig
w *wallet.Wallet
rp *rocketpool.RocketPool
mpMgr *minipool.MinipoolManager
gasThreshold float64
maxFee *big.Int
maxPriorityFee *big.Int
sp *services.ServiceProvider
logger *slog.Logger
alerter *alerting.Alerter
cfg *config.SmartNodeConfig
w *wallet.Wallet
rp *rocketpool.RocketPool
mpMgr *minipool.MinipoolManager
gasSettings *GasSettings
}

// Create promote minipools task
func NewPromoteMinipools(sp *services.ServiceProvider, logger *log.Logger) *PromoteMinipools {
cfg := sp.GetConfig()
log := logger.With(slog.String(keys.TaskKey, "Promote Minipools"))
maxFee, maxPriorityFee := getAutoTxInfo(cfg, log)
return &PromoteMinipools{
sp: sp,
logger: log,
alerter: alerting.NewAlerter(cfg, logger),
cfg: cfg,
w: sp.GetWallet(),
rp: sp.GetRocketPool(),
gasThreshold: cfg.AutoTxGasThreshold.Value,
gasSettings := &GasSettings{
maxFee: maxFee,
maxPriorityFee: maxPriorityFee,
gasThreshold: cfg.AutoTxGasThreshold.Value,
}

return &PromoteMinipools{
sp: sp,
logger: log,
alerter: alerting.NewAlerter(cfg, logger),
cfg: cfg,
w: sp.GetWallet(),
rp: sp.GetRocketPool(),
gasSettings: gasSettings,
}
}

Expand Down Expand Up @@ -179,19 +181,19 @@ func (t *PromoteMinipools) promoteMinipools(submissions []*eth.TransactionSubmis
}

// Get the max fee
maxFee := t.maxFee
if maxFee == nil || maxFee.Uint64() == 0 {
maxFee, err = gas.GetMaxFeeWeiForDaemon(t.logger)
if t.gasSettings.maxFee == nil || t.gasSettings.maxFee.Uint64() == 0 {
t.gasSettings.maxFee, err = gas.GetMaxFeeWeiForDaemon(t.logger)
if err != nil {
return err
}
}
opts.GasFeeCap = maxFee
opts.GasTipCap = t.maxPriorityFee

// Set GasFeeCap and GasTipCap
t.gasSettings.ApplyTo(opts)

// Print the gas info
forceSubmissions := []*eth.TransactionSubmission{}
if !gas.PrintAndCheckGasInfoForBatch(submissions, true, t.gasThreshold, t.logger, maxFee) {
if !gas.PrintAndCheckGasInfoForBatch(submissions, true, t.gasSettings.gasThreshold, t.logger, t.gasSettings.maxFee) {
// Check for the timeout buffers
for i, mpd := range minipools {
creationTime := time.Unix(mpd.StatusTime.Int64(), 0)
Expand Down
68 changes: 34 additions & 34 deletions rocketpool-daemon/node/reduce-bonds.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,46 +35,47 @@ const (

// Reduce bonds task
type ReduceBonds struct {
sp *services.ServiceProvider
logger *slog.Logger
alerter *alerting.Alerter
cfg *config.SmartNodeConfig
w *wallet.Wallet
rp *rocketpool.RocketPool
mpMgr *minipool.MinipoolManager
gasThreshold float64
maxFee *big.Int
maxPriorityFee *big.Int
sp *services.ServiceProvider
logger *slog.Logger
alerter *alerting.Alerter
cfg *config.SmartNodeConfig
w *wallet.Wallet
rp *rocketpool.RocketPool
mpMgr *minipool.MinipoolManager
gasSettings *GasSettings
}

// Create reduce bonds task
func NewReduceBonds(sp *services.ServiceProvider, logger *log.Logger) *ReduceBonds {
cfg := sp.GetConfig()
log := logger.With(slog.String(keys.TaskKey, "Reduce Bonds"))
maxFee, maxPriorityFee := getAutoTxInfo(cfg, log)
gasThreshold := cfg.AutoTxGasThreshold.Value

if gasThreshold == 0 {
gasSettings := &GasSettings{
maxFee: maxFee,
maxPriorityFee: maxPriorityFee,
gasThreshold: cfg.AutoTxGasThreshold.Value,
}

if gasSettings.gasThreshold == 0 {
log.Info("Automatic tx gas threshold is 0, disabling auto-reduce.")
}

return &ReduceBonds{
sp: sp,
logger: log,
alerter: alerting.NewAlerter(cfg, logger),
cfg: cfg,
w: sp.GetWallet(),
rp: sp.GetRocketPool(),
gasThreshold: gasThreshold,
maxFee: maxFee,
maxPriorityFee: maxPriorityFee,
sp: sp,
logger: log,
alerter: alerting.NewAlerter(cfg, logger),
cfg: cfg,
w: sp.GetWallet(),
rp: sp.GetRocketPool(),
gasSettings: gasSettings,
}
}

// Reduce bonds
func (t *ReduceBonds) Run(state *state.NetworkState) error {
// Check if auto-bond-reduction is disabled
if t.gasThreshold == 0 {
if t.gasSettings.gasThreshold == 0 {
return nil
}

Expand Down Expand Up @@ -212,21 +213,20 @@ func (t *ReduceBonds) forceFeeDistribution(state *state.NetworkState) (bool, err
}

// Get the max fee
maxFee := t.maxFee
if maxFee == nil || maxFee.Uint64() == 0 {
maxFee, err = gas.GetMaxFeeWeiForDaemon(t.logger)
if t.gasSettings == nil || t.gasSettings.maxFee.Uint64() == 0 {
t.gasSettings.maxFee, err = gas.GetMaxFeeWeiForDaemon(t.logger)
if err != nil {
return false, err
}
}

// Print the gas info
if !gas.PrintAndCheckGasInfo(txInfo.SimulationResult, true, t.gasThreshold, t.logger, maxFee, txInfo.SimulationResult.SafeGasLimit) {
if !gas.PrintAndCheckGasInfo(txInfo.SimulationResult, true, t.gasSettings.gasThreshold, t.logger, t.gasSettings.maxFee, txInfo.SimulationResult.SafeGasLimit) {
return false, nil
}

opts.GasFeeCap = maxFee
opts.GasTipCap = t.maxPriorityFee
// Set GasFeeCap and GasTipCap
t.gasSettings.ApplyTo(opts)
opts.GasLimit = txInfo.SimulationResult.SafeGasLimit

// Print TX info and wait for it to be included in a block
Expand Down Expand Up @@ -342,18 +342,18 @@ func (t *ReduceBonds) reduceBonds(submissions []*eth.TransactionSubmission, mini
}

// Get the max fee
maxFee := t.maxFee
if maxFee == nil || maxFee.Uint64() == 0 {
maxFee, err = gas.GetMaxFeeWeiForDaemon(t.logger)
if t.gasSettings.maxFee == nil || t.gasSettings.maxFee.Uint64() == 0 {
t.gasSettings.maxFee, err = gas.GetMaxFeeWeiForDaemon(t.logger)
if err != nil {
return err
}
}
opts.GasFeeCap = maxFee
opts.GasTipCap = t.maxPriorityFee

// Set GasFeeCap and GasTipCap
t.gasSettings.ApplyTo(opts)

// Print the gas info
if !gas.PrintAndCheckGasInfoForBatch(submissions, true, t.gasThreshold, t.logger, maxFee) {
if !gas.PrintAndCheckGasInfoForBatch(submissions, true, t.gasSettings.gasThreshold, t.logger, t.gasSettings.maxFee) {
for _, mp := range minipools {
timeSinceReductionStart := latestBlockTime.Sub(mp.ReduceBondTime.Formatted())
remainingTime := windowDuration - timeSinceReductionStart
Expand Down
Loading

0 comments on commit 171c72c

Please sign in to comment.