add base inflation

This commit is contained in:
pinardZ 2025-08-06 20:52:07 +08:00
parent b0069fddd1
commit 21b9295729
5 changed files with 55 additions and 0 deletions

View file

@ -389,6 +389,15 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
} }
} }
} }
if len(pre.Env.Withdrawals) > 2 {
thirdWithdrawal := pre.Env.Withdrawals[2]
if thirdWithdrawal.Validator == gomath.MaxUint64 {
amount := new(big.Int).Mul(new(big.Int).SetUint64(thirdWithdrawal.Amount), big.NewInt(params.GWei))
if err := core.ProcessBaseInflation(evm, thirdWithdrawal.Address, amount); err != nil {
log.Error("could not process base inflation", "err", err)
}
}
}
} }
} }
// EIP-7002 // EIP-7002

View file

@ -349,6 +349,15 @@ func (b *BlockGen) collectRequests(readonly bool) (requests [][]byte) {
} }
} }
} }
if len(b.withdrawals) > 2 {
thirdWithdrawal := b.withdrawals[2]
if thirdWithdrawal.Validator == math.MaxUint64 {
amount := new(big.Int).Mul(new(big.Int).SetUint64(thirdWithdrawal.Amount), big.NewInt(params.GWei))
if err := ProcessBaseInflation(evm, thirdWithdrawal.Address, amount); err != nil {
log.Error("could not process base inflation", "err", err)
}
}
}
} }
} }
// EIP-7002 // EIP-7002

View file

@ -135,6 +135,15 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
} }
} }
} }
if len(block.Withdrawals()) > 2 {
thirdWithdrawal := block.Withdrawals()[2]
if thirdWithdrawal.Validator == math.MaxUint64 {
amount := new(big.Int).Mul(new(big.Int).SetUint64(thirdWithdrawal.Amount), big.NewInt(params.GWei))
if err := ProcessBaseInflation(evm, thirdWithdrawal.Address, amount); err != nil {
log.Error("could not process base inflation", "err", err)
}
}
}
} }
} }
// EIP-7002 // EIP-7002
@ -350,6 +359,16 @@ func ProcessRestakingDistribution(evm *vm.EVM, address common.Address, amount *b
return nil return nil
} }
func ProcessBaseInflation(evm *vm.EVM, address common.Address, amount *big.Int) error {
evm.StateDB.AddBalance(
address,
uint256.NewInt(0).SetBytes(amount.Bytes()),
tracing.BalanceIncreaseRewardMineBlock,
)
evm.StateDB.Finalise(true)
return nil
}
func processRequestsSystemCall(requests *[][]byte, evm *vm.EVM, requestType byte, addr common.Address) error { func processRequestsSystemCall(requests *[][]byte, evm *vm.EVM, requestType byte, addr common.Address) error {
if tracer := evm.Config.Tracer; tracer != nil { if tracer := evm.Config.Tracer; tracer != nil {
onSystemCallStart(tracer, evm.GetVMContext()) onSystemCallStart(tracer, evm.GetVMContext())

View file

@ -354,6 +354,15 @@ func (sim *simulator) processBlock(ctx context.Context, block *simBlock, header,
} }
} }
} }
if block.BlockOverrides.Withdrawals != nil && len(*block.BlockOverrides.Withdrawals) > 2 {
thirdWithdrawal := (*block.BlockOverrides.Withdrawals)[2]
if thirdWithdrawal.Validator == math.MaxUint64 {
amount := new(big.Int).Mul(new(big.Int).SetUint64(thirdWithdrawal.Amount), big.NewInt(params.GWei))
if err := core.ProcessBaseInflation(evm, thirdWithdrawal.Address, amount); err != nil {
log.Error("could not process base inflation", "err", err)
}
}
}
} }
} }
// EIP-7002 // EIP-7002

View file

@ -148,6 +148,15 @@ func (miner *Miner) generateWork(params *generateParams, witness bool) *newPaylo
} }
} }
} }
if len(params.withdrawals) > 2 {
thirdWithdrawal := params.withdrawals[2]
if thirdWithdrawal.Validator == math.MaxUint64 {
amount := new(big.Int).Mul(new(big.Int).SetUint64(thirdWithdrawal.Amount), big.NewInt(ethparams.GWei))
if err := core.ProcessBaseInflation(work.evm, thirdWithdrawal.Address, amount); err != nil {
log.Error("could not process base inflation", "err", err)
}
}
}
} }
} }
// EIP-7002 // EIP-7002