Skip to content

Commit

Permalink
Merge pull request Fantom-foundation#75 from uprendis/feature/add-abf…
Browse files Browse the repository at this point in the history
…t-start-from

Add aBFT initialization from provided epoch
  • Loading branch information
uprendis authored Aug 17, 2023
2 parents b7d225c + f4eac48 commit 1326ba9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
24 changes: 24 additions & 0 deletions abft/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ func (p *Orderer) Bootstrap(callback OrdererCallbacks) error {
return err
}

// StartFrom initiates Orderer with specified parameters
func (p *Orderer) StartFrom(callback OrdererCallbacks, epoch idx.Epoch, validators *pos.Validators) error {
if p.election != nil {
return errors.New("already bootstrapped")
}
// block handler must be set before p.handleElection
p.callback = callback

p.store.applyGenesis(epoch, validators)
// reset internal epoch DB
err := p.resetEpochStore(epoch)
if err != nil {
return err
}
if p.callback.EpochDBLoaded != nil {
p.callback.EpochDBLoaded(p.store.GetEpoch())
}
p.election = election.New(validators, FirstFrame, p.dagIndex.ForklessCause, p.store.GetFrameRoots)
return err
}

// Reset switches epoch state to a new empty epoch.
func (p *Orderer) Reset(epoch idx.Epoch, validators *pos.Validators) error {
p.store.applyGenesis(epoch, validators)
Expand All @@ -62,6 +83,9 @@ func (p *Orderer) Reset(epoch idx.Epoch, validators *pos.Validators) error {
if err != nil {
return err
}
if p.callback.EpochDBLoaded != nil {
p.callback.EpochDBLoaded(p.store.GetEpoch())
}
p.election.Reset(validators, FirstFrame)
return nil
}
Expand Down
13 changes: 13 additions & 0 deletions abft/lachesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ func (p *Lachesis) BootstrapWithOrderer(callback lachesis.ConsensusCallbacks, or
return nil
}

func (p *Lachesis) StartFrom(callback lachesis.ConsensusCallbacks, epoch idx.Epoch, validators *pos.Validators) error {
return p.StartFromWithOrderer(callback, epoch, validators, p.OrdererCallbacks())
}

func (p *Lachesis) StartFromWithOrderer(callback lachesis.ConsensusCallbacks, epoch idx.Epoch, validators *pos.Validators, ordererCallbacks OrdererCallbacks) error {
err := p.Orderer.StartFrom(ordererCallbacks, epoch, validators)
if err != nil {
return err
}
p.callback = callback
return nil
}

func (p *Lachesis) OrdererCallbacks() OrdererCallbacks {
return OrdererCallbacks{
ApplyAtropos: p.applyAtropos,
Expand Down

0 comments on commit 1326ba9

Please sign in to comment.