good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit c3ed07ca authored by Enrique Jose  Avila Asapche's avatar Enrique Jose Avila Asapche Committed by GitHub
Browse files

Implementing basic unwind process for Proof-of-stake (#3083)

* initial commmit

* gofmt

* flipped if statement

* flipped if statement (forgot to save)

* passing unwinding to status ch

* added unwinding constant

* took out unwinding

* added statusCh

* added a return statement and a second part to the if statement

* checking for parent hash

* checking for parent hash

* changed check to check for parentHash

* staged wrong file

* changed header check to parentHash check

* channged blockhash name to a better name

* changed it to check for header.Hash()

* changed name of blocknumber to blockHash

* changed bad block to common.Hash{}
parent bbb3cc97
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ import (
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
"github.com/ledgerwatch/erigon/ethdb/privateapi"
"github.com/ledgerwatch/erigon/p2p/enode"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/rlp"
......@@ -30,6 +31,7 @@ import (
type HeadersCfg struct {
db kv.RwDB
hd *headerdownload.HeaderDownload
statusCh chan privateapi.ExecutionStatus
chainConfig params.ChainConfig
headerReqSend func(context.Context, *headerdownload.HeaderRequest) (enode.ID, bool)
announceNewHashes func(context.Context, []headerdownload.Announce)
......@@ -45,6 +47,7 @@ type HeadersCfg struct {
func StageHeadersCfg(
db kv.RwDB,
headerDownload *headerdownload.HeaderDownload,
statusCh chan privateapi.ExecutionStatus,
chainConfig params.ChainConfig,
headerReqSend func(context.Context, *headerdownload.HeaderRequest) (enode.ID, bool),
announceNewHashes func(context.Context, []headerdownload.Announce),
......@@ -59,6 +62,7 @@ func StageHeadersCfg(
return HeadersCfg{
db: db,
hd: headerDownload,
statusCh: statusCh,
chainConfig: chainConfig,
headerReqSend: headerReqSend,
announceNewHashes: announceNewHashes,
......@@ -127,7 +131,25 @@ func HeadersDownward(
log.Info("Waiting for payloads...")
header := <-cfg.reverseDownloadCh
*cfg.waitingPosHeaders = false
defer tx.Commit()
headerNumber := header.Number.Uint64()
blockHash, err := rawdb.ReadCanonicalHash(tx, headerNumber)
if err != nil {
return err
}
// Do we need to unwind? (TODO)
if s.BlockNumber >= headerNumber && header.Hash() != blockHash {
u.UnwindTo(headerNumber-1, common.Hash{})
cfg.statusCh <- privateapi.ExecutionStatus{
HeadHash: header.ParentHash,
Status: privateapi.Syncing,
}
return nil
}
// Write current payload
rawdb.WriteHeader(tx, &header)
......
......@@ -275,6 +275,7 @@ func MockWithEverything(t *testing.T, gspec *core.Genesis, key *ecdsa.PrivateKey
stagedsync.DefaultStages(mock.Ctx, prune, stagedsync.StageHeadersCfg(
mock.DB,
mock.downloader.Hd,
make(chan privateapi.ExecutionStatus),
*mock.ChainConfig,
sendHeaderRequest,
propagateNewBlockHashes,
......
......@@ -244,6 +244,7 @@ func NewStagedSync(
stagedsync.DefaultStages(ctx, cfg.Prune, stagedsync.StageHeadersCfg(
db,
controlServer.Hd,
statusCh,
*controlServer.ChainConfig,
controlServer.SendHeaderRequest,
controlServer.PropagateNewBlockHashes,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment