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:
David 2025-05-13 09:32:50 +08:00 committed by GitHub
parent c091dd6c8f
commit 187f85d772
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 10 deletions

View file

@ -26,7 +26,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
go-version: '1.24'
- name: Lint
run: make lint

View file

@ -20,12 +20,14 @@ func (l L1Origin) MarshalJSON() ([]byte, error) {
L2BlockHash common.Hash `json:"l2BlockHash"`
L1BlockHeight *math.HexOrDecimal256 `json:"l1BlockHeight" rlp:"optional"`
L1BlockHash common.Hash `json:"l1BlockHash" rlp:"optional"`
BuildPayloadArgsID [8]byte `json:"buildPayloadArgsID" rlp:"optional"`
}
var enc L1Origin
enc.BlockID = (*math.HexOrDecimal256)(l.BlockID)
enc.L2BlockHash = l.L2BlockHash
enc.L1BlockHeight = (*math.HexOrDecimal256)(l.L1BlockHeight)
enc.L1BlockHash = l.L1BlockHash
enc.BuildPayloadArgsID = l.BuildPayloadArgsID
return json.Marshal(&enc)
}
@ -36,6 +38,7 @@ func (l *L1Origin) UnmarshalJSON(input []byte) error {
L2BlockHash *common.Hash `json:"l2BlockHash"`
L1BlockHeight *math.HexOrDecimal256 `json:"l1BlockHeight" rlp:"optional"`
L1BlockHash *common.Hash `json:"l1BlockHash" rlp:"optional"`
BuildPayloadArgsID *[8]byte `json:"buildPayloadArgsID" rlp:"optional"`
}
var dec L1Origin
if err := json.Unmarshal(input, &dec); err != nil {
@ -54,5 +57,8 @@ func (l *L1Origin) UnmarshalJSON(input []byte) error {
if dec.L1BlockHash != nil {
l.L1BlockHash = *dec.L1BlockHash
}
if dec.BuildPayloadArgsID != nil {
l.BuildPayloadArgsID = *dec.BuildPayloadArgsID
}
return nil
}

View file

@ -33,6 +33,15 @@ type L1Origin struct {
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"`
L2BlockHash common.Hash `json:"l2BlockHash"`
L1BlockHeight *big.Int `json:"l1BlockHeight" rlp:"optional"`
L1BlockHash common.Hash `json:"l1BlockHash" rlp:"optional"`
}
type l1OriginMarshaling struct {
@ -64,9 +73,25 @@ func ReadL1Origin(db ethdb.KeyValueReader, blockID *big.Int) (*L1Origin, error)
return nil, nil
}
// First try to decode the new version (with new fields).
l1Origin := new(L1Origin)
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