Skip to content

Commit

Permalink
fix: reorg check by GetJustifiedNumberAndHash (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
setunapo committed May 31, 2023
1 parent e7d0c7b commit f0ac7c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
18 changes: 9 additions & 9 deletions params/chainspecs/rialto.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
"ramanujanBlock": 0,
"nielsBlock": 0,
"__comment1__": "leave enough time to update the genesis hash and restart",
"mirrorSyncBlock": 201,
"brunoBlock": 210,
"eulerBlock": 220,
"nanoBlock": 230,
"gibbsBlock": 240,
"moranBlock": 250,
"planckBlock": 260,
"mirrorSyncBlock": 0,
"brunoBlock": 0,
"eulerBlock": 0,
"nanoBlock": 0,
"gibbsBlock": 3,
"moranBlock": 4,
"planckBlock": 5,
"__comment2__": "lubanBlock%200 != 0, e.g. lubanBlock == 400 is unacceptable",
"lubanBlock": 270,
"platoblock": 1000000,
"lubanBlock": 6,
"platoblock": 7,
"parlia": {
"DBPath": "",
"InMemory": false,
Expand Down
2 changes: 1 addition & 1 deletion turbo/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewNodConfigUrfave(ctx *cli.Context) *nodecfg.Config {
case networkname.ChapelChainName:
log.Info("Starting Erigon on Chapel testnet...")
case networkname.RialtoChainName:
log.Info("Starting Erigon on Chapel testnet...")
log.Info("Starting Erigon on Rialto testnet...")
case networkname.DevChainName:
log.Info("Starting Erigon in ephemeral dev mode...")
case networkname.MumbaiChainName:
Expand Down
17 changes: 10 additions & 7 deletions turbo/stages/headerdownload/header_algos.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,10 @@ func (hi *HeaderInserter) FeedHeaderPoW(db kv.StatelessRwTx, headerReader servic
return nil, fmt.Errorf("could not find parent with hash %x and height %d for header %x %d", header.ParentHash, blockHeight-1, hash, blockHeight)
}

if err = db.Put(kv.Headers, dbutils.HeaderKey(blockHeight, hash), headerRaw); err != nil {
return nil, fmt.Errorf("[%s] failed to store header: %w", hi.logPrefix, err)
}

isWithFastFinality := true
reorgFunc := func() (bool, error) {
if p, ok := engine.(consensus.PoSA); ok {
Expand All @@ -883,8 +887,12 @@ func (hi *HeaderInserter) FeedHeaderPoW(db kv.StatelessRwTx, headerReader servic
}
}
if config.IsPlato(hi.highest) {
if justifiedNumberGot, _, err := p.GetJustifiedNumberAndHash(consensusHeaderReader, header); err == nil {
curJustifiedNumber = justifiedNumberGot
if highestHeader, err := headerReader.Header(context.Background(), db, hi.highestHash, hi.highest); highestHeader != nil {
if justifiedNumberGot, _, err := p.GetJustifiedNumberAndHash(consensusHeaderReader, highestHeader); err == nil {
curJustifiedNumber = justifiedNumberGot
}
} else {
log.Error("FeedHeaderPoW Get highestHeader fail", "err", err, "hi.highest", hi.highest, "hi.highestHash", hi.highestHash)
}
}
if justifiedNumber == curJustifiedNumber {
Expand Down Expand Up @@ -927,11 +935,6 @@ func (hi *HeaderInserter) FeedHeaderPoW(db kv.StatelessRwTx, headerReader servic
if err = rawdb.WriteTd(db, hash, blockHeight, td); err != nil {
return nil, fmt.Errorf("[%s] failed to WriteTd: %w", hi.logPrefix, err)
}

if err = db.Put(kv.Headers, dbutils.HeaderKey(blockHeight, hash), headerRaw); err != nil {
return nil, fmt.Errorf("[%s] failed to store header: %w", hi.logPrefix, err)
}

hi.prevHash = hash
return td, nil
}
Expand Down

0 comments on commit f0ac7c5

Please sign in to comment.