mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
feat(rawdb): introduce BuildPayloadArgsID to L1Origin (#426)
* feat(rawdb): introduce `BuildPayloadArgsID` to `L1Origin` * Update core/rawdb/taiko_l1_origin.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * feat: update ci * feat: fmt * feat: update BuildPayloadArgsID --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
c091dd6c8f
commit
187f85d772
3 changed files with 41 additions and 10 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -26,7 +26,7 @@ jobs:
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '1.21'
|
go-version: '1.24'
|
||||||
|
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: make lint
|
run: make lint
|
||||||
|
|
|
||||||
|
|
@ -16,26 +16,29 @@ var _ = (*l1OriginMarshaling)(nil)
|
||||||
// MarshalJSON marshals as JSON.
|
// MarshalJSON marshals as JSON.
|
||||||
func (l L1Origin) MarshalJSON() ([]byte, error) {
|
func (l L1Origin) MarshalJSON() ([]byte, error) {
|
||||||
type L1Origin struct {
|
type L1Origin struct {
|
||||||
BlockID *math.HexOrDecimal256 `json:"blockID" gencodec:"required"`
|
BlockID *math.HexOrDecimal256 `json:"blockID" gencodec:"required"`
|
||||||
L2BlockHash common.Hash `json:"l2BlockHash"`
|
L2BlockHash common.Hash `json:"l2BlockHash"`
|
||||||
L1BlockHeight *math.HexOrDecimal256 `json:"l1BlockHeight" rlp:"optional"`
|
L1BlockHeight *math.HexOrDecimal256 `json:"l1BlockHeight" rlp:"optional"`
|
||||||
L1BlockHash common.Hash `json:"l1BlockHash" rlp:"optional"`
|
L1BlockHash common.Hash `json:"l1BlockHash" rlp:"optional"`
|
||||||
|
BuildPayloadArgsID [8]byte `json:"buildPayloadArgsID" rlp:"optional"`
|
||||||
}
|
}
|
||||||
var enc L1Origin
|
var enc L1Origin
|
||||||
enc.BlockID = (*math.HexOrDecimal256)(l.BlockID)
|
enc.BlockID = (*math.HexOrDecimal256)(l.BlockID)
|
||||||
enc.L2BlockHash = l.L2BlockHash
|
enc.L2BlockHash = l.L2BlockHash
|
||||||
enc.L1BlockHeight = (*math.HexOrDecimal256)(l.L1BlockHeight)
|
enc.L1BlockHeight = (*math.HexOrDecimal256)(l.L1BlockHeight)
|
||||||
enc.L1BlockHash = l.L1BlockHash
|
enc.L1BlockHash = l.L1BlockHash
|
||||||
|
enc.BuildPayloadArgsID = l.BuildPayloadArgsID
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalJSON unmarshals from JSON.
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (l *L1Origin) UnmarshalJSON(input []byte) error {
|
func (l *L1Origin) UnmarshalJSON(input []byte) error {
|
||||||
type L1Origin struct {
|
type L1Origin struct {
|
||||||
BlockID *math.HexOrDecimal256 `json:"blockID" gencodec:"required"`
|
BlockID *math.HexOrDecimal256 `json:"blockID" gencodec:"required"`
|
||||||
L2BlockHash *common.Hash `json:"l2BlockHash"`
|
L2BlockHash *common.Hash `json:"l2BlockHash"`
|
||||||
L1BlockHeight *math.HexOrDecimal256 `json:"l1BlockHeight" rlp:"optional"`
|
L1BlockHeight *math.HexOrDecimal256 `json:"l1BlockHeight" rlp:"optional"`
|
||||||
L1BlockHash *common.Hash `json:"l1BlockHash" rlp:"optional"`
|
L1BlockHash *common.Hash `json:"l1BlockHash" rlp:"optional"`
|
||||||
|
BuildPayloadArgsID *[8]byte `json:"buildPayloadArgsID" rlp:"optional"`
|
||||||
}
|
}
|
||||||
var dec L1Origin
|
var dec L1Origin
|
||||||
if err := json.Unmarshal(input, &dec); err != nil {
|
if err := json.Unmarshal(input, &dec); err != nil {
|
||||||
|
|
@ -54,5 +57,8 @@ func (l *L1Origin) UnmarshalJSON(input []byte) error {
|
||||||
if dec.L1BlockHash != nil {
|
if dec.L1BlockHash != nil {
|
||||||
l.L1BlockHash = *dec.L1BlockHash
|
l.L1BlockHash = *dec.L1BlockHash
|
||||||
}
|
}
|
||||||
|
if dec.BuildPayloadArgsID != nil {
|
||||||
|
l.BuildPayloadArgsID = *dec.BuildPayloadArgsID
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,15 @@ func l1OriginKey(blockID *big.Int) []byte {
|
||||||
|
|
||||||
// L1Origin represents a L1Origin of a L2 block.
|
// L1Origin represents a L1Origin of a L2 block.
|
||||||
type L1Origin struct {
|
type L1Origin struct {
|
||||||
|
BlockID *big.Int `json:"blockID" gencodec:"required"`
|
||||||
|
L2BlockHash common.Hash `json:"l2BlockHash"`
|
||||||
|
L1BlockHeight *big.Int `json:"l1BlockHeight" rlp:"optional"`
|
||||||
|
L1BlockHash common.Hash `json:"l1BlockHash" rlp:"optional"`
|
||||||
|
BuildPayloadArgsID [8]byte `json:"buildPayloadArgsID" rlp:"optional"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// L1OriginLegacy represents a legacy L1Origin of a L2 block.
|
||||||
|
type L1OriginLegacy struct {
|
||||||
BlockID *big.Int `json:"blockID" gencodec:"required"`
|
BlockID *big.Int `json:"blockID" gencodec:"required"`
|
||||||
L2BlockHash common.Hash `json:"l2BlockHash"`
|
L2BlockHash common.Hash `json:"l2BlockHash"`
|
||||||
L1BlockHeight *big.Int `json:"l1BlockHeight" rlp:"optional"`
|
L1BlockHeight *big.Int `json:"l1BlockHeight" rlp:"optional"`
|
||||||
|
|
@ -64,9 +73,25 @@ func ReadL1Origin(db ethdb.KeyValueReader, blockID *big.Int) (*L1Origin, error)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// First try to decode the new version (with new fields).
|
||||||
l1Origin := new(L1Origin)
|
l1Origin := new(L1Origin)
|
||||||
if err := rlp.Decode(bytes.NewReader(data), l1Origin); err != nil {
|
if err := rlp.Decode(bytes.NewReader(data), l1Origin); err != nil {
|
||||||
return nil, fmt.Errorf("invalid L1Origin RLP bytes: %w", err)
|
// If decoding the new version fails, try to decode the legacy version (without new fields).
|
||||||
|
l1OriginLegacy := new(L1OriginLegacy)
|
||||||
|
if err := rlp.Decode(bytes.NewReader(data), &l1OriginLegacy); err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid legacy L1Origin RLP bytes: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If decoding legacy version succeeds, manually
|
||||||
|
// construct the new L1Origin with default values for the new fields.
|
||||||
|
l1Origin = &L1Origin{
|
||||||
|
BlockID: l1OriginLegacy.BlockID,
|
||||||
|
L2BlockHash: l1OriginLegacy.L2BlockHash,
|
||||||
|
L1BlockHeight: l1OriginLegacy.L1BlockHeight,
|
||||||
|
L1BlockHash: l1OriginLegacy.L1BlockHash,
|
||||||
|
// Set BuildPayloadArgsID to an empty hash as the intended default for legacy L1Origin conversions.
|
||||||
|
BuildPayloadArgsID: [8]byte{},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return l1Origin, nil
|
return l1Origin, nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue