Skip to content

Commit

Permalink
feat(core): changes based on the latest block.extradata format (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Aug 8, 2024
1 parent 124fde7 commit a875cc8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 40 deletions.
3 changes: 1 addition & 2 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 4 additions & 17 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Loading

0 comments on commit a875cc8

Please sign in to comment.