Skip to content

Commit

Permalink
Made it so pick ph only happens in zones
Browse files Browse the repository at this point in the history
  • Loading branch information
kiltsonfire committed May 17, 2023
1 parent a2b5099 commit 078b897
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 115 deletions.
8 changes: 4 additions & 4 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (c *Core) InsertChain(blocks types.Blocks) (int, error) {
return idx, err
}
if order == nodeCtx {
newPendingEtxs, err := c.sl.Append(block.Header(), types.EmptyHeader(), common.Hash{}, false, nil)
newPendingEtxs, _, err := c.sl.Append(block.Header(), types.EmptyHeader(), common.Hash{}, false, nil)
if err == nil {
// If we have a dom, send the dom any pending ETXs which will become
// referencable by this block. When this block is referenced in the dom's
Expand Down Expand Up @@ -243,8 +243,8 @@ func (c *Core) WriteBlock(block *types.Block) {
}
}

func (c *Core) Append(header *types.Header, domPendingHeader *types.Header, domTerminus common.Hash, domOrigin bool, newInboundEtxs types.Transactions) (types.Transactions, error) {
newPendingEtxs, err := c.sl.Append(header, domPendingHeader, domTerminus, domOrigin, newInboundEtxs)
func (c *Core) Append(header *types.Header, domPendingHeader *types.Header, domTerminus common.Hash, domOrigin bool, newInboundEtxs types.Transactions) (types.Transactions, bool, error) {
newPendingEtxs, subReorg, err := c.sl.Append(header, domPendingHeader, domTerminus, domOrigin, newInboundEtxs)
if err != nil {
if err.Error() == ErrBodyNotFound.Error() {
c.sl.missingBodyFeed.Send(header)
Expand All @@ -253,7 +253,7 @@ func (c *Core) Append(header *types.Header, domPendingHeader *types.Header, domT
c.sl.missingParentFeed.Send(header.ParentHash())
}
}
return newPendingEtxs, err
return newPendingEtxs, subReorg, err
}

// ConstructLocalBlock takes a header and construct the Block locally
Expand Down
29 changes: 1 addition & 28 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,31 +616,6 @@ func DeletePhCacheTermini(db ethdb.KeyValueWriter, hash common.Hash) {
}
}

// ReadPhCacheEntropy retrieves a ph cache total entropy corresponding to the hash.
func ReadPhCacheEntropy(db ethdb.Reader, hash common.Hash) *big.Int {
data, _ := db.Get(phCacheEntropyKey(hash))
if len(data) == 0 {
return nil
}
s := new(big.Int)
if err := rlp.Decode(bytes.NewReader(data), s); err != nil {
log.Error("Invalid ph cache entropy RLP", "hash", hash, "err", err)
return nil
}
return s
}

// WritePhCacheEntropy stores the total entropy of a ph cache key into the database.
func WritePhCacheEntropy(db ethdb.KeyValueWriter, hash common.Hash, s *big.Int) {
data, err := rlp.EncodeToBytes(s)
if err != nil {
log.Fatal("Failed to RLP encode ph cache entropy", "err", err)
}
if err := db.Put(phCacheEntropyKey(hash), data); err != nil {
log.Fatal("Failed to store ph cache entropy", "err", err)
}
}

// ReadPhCache retreive's the heads hashes of the blockchain.
func ReadPhCache(db ethdb.Reader) map[common.Hash]types.PendingHeader {
data, _ := db.Get(phCacheKey)
Expand All @@ -658,8 +633,7 @@ func ReadPhCache(db ethdb.Reader) map[common.Hash]types.PendingHeader {
for _, hash := range hashes {
header := ReadPendingHeader(db, hash)
termini := ReadPhCacheTermini(db, hash)
entropy := ReadPhCacheEntropy(db, hash)
pendingHeader := types.PendingHeader{Header: header, Termini: termini, Entropy: entropy}
pendingHeader := types.PendingHeader{Header: header, Termini: termini}
phCache[hash] = pendingHeader
}
return phCache
Expand All @@ -672,7 +646,6 @@ func WritePhCache(db ethdb.KeyValueWriter, phCache map[common.Hash]types.Pending
hashes = append(hashes, hash)
WritePendingHeader(db, hash, pendingHeader.Header)
WritePhCacheTermini(db, hash, pendingHeader.Termini)
WritePhCacheEntropy(db, hash, pendingHeader.Entropy)
}

data, err := rlp.EncodeToBytes(hashes)
Expand Down
6 changes: 0 additions & 6 deletions core/rawdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ var (
pbBodyPrefix = []byte("pb") // pbBodyPrefix + hash -> *types.Body
pbBodyHashPrefix = []byte("pbKey") // pbBodyPrefix -> []common.Hash
phTerminiPrefix = []byte("pht") // phTerminiPrefix + hash -> []common.Hash
phEntropyPrefix = []byte("pt") // phEntropyPrefix + hash -> *big.Int
phBodyPrefix = []byte("pc") // phBodyPrefix + hash -> []common.Hash + Td
terminiPrefix = []byte("tk") //terminiPrefix + hash -> []common.Hash

Expand Down Expand Up @@ -204,11 +203,6 @@ func headerTDKey(number uint64, hash common.Hash) []byte {
return append(headerKey(number, hash), headerTDSuffix...)
}

// phCacheEntropyKey = phEntropyPrefix + hash
func phCacheEntropyKey(hash common.Hash) []byte {
return append(phEntropyPrefix, hash.Bytes()...)
}

// headerHashKey = headerPrefix + num (uint64 big endian) + headerHashSuffix
func headerHashKey(number uint64) []byte {
return append(append(headerPrefix, encodeBlockNumber(number)...), headerHashSuffix...)
Expand Down
Loading

0 comments on commit 078b897

Please sign in to comment.