Skip to content

Commit

Permalink
Added inboundetxs to database for uncles and use it in the case of sw…
Browse files Browse the repository at this point in the history
…itch
  • Loading branch information
gameofpointers committed Aug 23, 2023
1 parent 1faf905 commit 9b3cc74
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
33 changes: 33 additions & 0 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1347,3 +1347,36 @@ func DeleteBadHashesList(db ethdb.KeyValueWriter) {
log.Fatal("Failed to delete badHashesList", "err", err)
}
}

// WriteInboundEtxs stores the inbound etxs for a given dom block hashes
func WriteInboundEtxs(db ethdb.KeyValueWriter, hash common.Hash, inboundEtxs types.Transactions) {
data, err := rlp.EncodeToBytes(inboundEtxs)
if err != nil {
log.Fatal("Failed to RLP encode inbound etxs", "err", err)
}
if err := db.Put(inboundEtxsKey(hash), data); err != nil {
log.Fatal("Failed to store badHashesList", "err", err)
}
}

// ReadInboundEtxs reads the inbound etxs from the database
func ReadInboundEtxs(db ethdb.Reader, hash common.Hash) types.Transactions {
// Try to look up the data in leveldb.
data, _ := db.Get(inboundEtxsKey(hash))
if len(data) == 0 {
return nil
}
inboundEtxs := types.Transactions{}
if err := rlp.Decode(bytes.NewReader(data), &inboundEtxs); err != nil {
log.Error("Invalid inbound etxs on read", "hash", hash, "err", err)
return nil
}
return inboundEtxs
}

// DeleteInboundEtxs deletes the inbound etxs from the database
func DeleteInboundEtxs(db ethdb.KeyValueWriter, hash common.Hash) {
if err := db.Delete(inboundEtxsKey(hash)); err != nil {
log.Fatal("Failed to delete inbound etxs", "err", err)
}
}
5 changes: 5 additions & 0 deletions core/rawdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var (
phBodyPrefix = []byte("pc") // phBodyPrefix + hash -> []common.Hash + Td
terminiPrefix = []byte("tk") //terminiPrefix + hash -> []common.Hash
badHashesListPrefix = []byte("bh")
inboundEtxsPrefix = []byte("ie") // inboundEtxsPrefix + hash -> types.Transactions

blockBodyPrefix = []byte("b") // blockBodyPrefix + num (uint64 big endian) + hash -> block body
blockReceiptsPrefix = []byte("r") // blockReceiptsPrefix + num (uint64 big endian) + hash -> block receipts
Expand Down Expand Up @@ -303,3 +304,7 @@ func manifestKey(hash common.Hash) []byte {
func bloomKey(hash common.Hash) []byte {
return append(bloomPrefix, hash.Bytes()...)
}

func inboundEtxsKey(hash common.Hash) []byte {
return append(inboundEtxsPrefix, hash.Bytes()...)
}
6 changes: 6 additions & 0 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ func (sl *Slice) Append(header *types.Header, domPendingHeader *types.Header, do

subReorg = sl.miningStrategy(bestPh, block)

if order < nodeCtx {
// Store the inbound etxs for dom blocks that did not get picked and use
// it in the future if dom switch happens
rawdb.WriteInboundEtxs(batch, block.Hash(), newInboundEtxs.FilterToLocation(common.NodeLocation))
}

// Upate the local pending header
pendingHeaderWithTermini, err = sl.generateSlicePendingHeader(block, newTermini, domPendingHeader, domOrigin, false)
if err != nil {
Expand Down

0 comments on commit 9b3cc74

Please sign in to comment.