feat(core): changes based on the latest block.extradata format (#295)

This commit is contained in:
David 2024-08-08 11:38:43 +08:00 committed by GitHub
parent 124fde7e02
commit a875cc83b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 40 deletions

View file

@ -172,8 +172,7 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
// CHANGE(taiko): decode the basefeeSharingPctg config from the extradata, and
// add it to the Message, if its an ontake block.
if config.IsOntake(header.Number) {
basefeeSharingPctg, _ := DecodeOntakeExtraData(header.Extra)
msg.BasefeeSharingPctg = basefeeSharingPctg
msg.BasefeeSharingPctg = DecodeOntakeExtraData(header.Extra)
}
// Create a new context to be used in the EVM environment
blockContext := NewEVMBlockContext(header, bc, author)

View file

@ -538,21 +538,8 @@ func (st *StateTransition) getTreasuryAddress() common.Address {
)
}
// DecodeOntakeExtraData decodes an ontake block's extradata,
// returns basefeeSharingPctg and blockGasTargetMillion configurations.
func DecodeOntakeExtraData(extradata []byte) (uint8, uint8) {
// Convert []byte to *big.Int
extra := new(big.Int).SetBytes(extradata)
// Define the masks.
blockGasTargetMillionMask := big.NewInt(0xFF) // 8 bits mask for _blockGasTargetMillion
basefeeSharingPctgMask := big.NewInt(0xFF) // 8 bits mask for _basefeeSharingPctg
// Extract _blockGasTargetMillion.
blockGasTargetMillion := new(big.Int).And(extra, blockGasTargetMillionMask).Uint64()
// Shift right by 8 bits to get the _basefeeSharingPctg part.
basefeeSharingPctg := new(big.Int).Rsh(extra, 8).And(basefeeSharingPctgMask, basefeeSharingPctgMask).Uint64()
return uint8(basefeeSharingPctg), uint8(blockGasTargetMillion)
// DecodeOntakeExtraData decodes an ontake block's extradata, returns basefeeSharingPctg configurations,
// the corresponding enocding function in protocol is `LibProposing._encodeGasConfigs`.
func DecodeOntakeExtraData(extradata []byte) uint8 {
return uint8(new(big.Int).SetBytes(extradata).Uint64())
}

File diff suppressed because one or more lines are too long