mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-10 14:03:46 +00:00
new: add without-heimdall flag
This commit is contained in:
parent
49aff6eca7
commit
480d7ea99c
1 changed files with 73 additions and 18 deletions
|
|
@ -656,7 +656,7 @@ func (c *Bor) Prepare(chain consensus.ChainReader, header *types.Header) error {
|
||||||
// rewards given.
|
// rewards given.
|
||||||
func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) {
|
func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) {
|
||||||
headerNumber := header.Number.Uint64()
|
headerNumber := header.Number.Uint64()
|
||||||
if !c.WithoutHeimdall && headerNumber%c.config.Sprint == 0 {
|
if headerNumber%c.config.Sprint == 0 {
|
||||||
cx := chainContext{Chain: chain, Bor: c}
|
cx := chainContext{Chain: chain, Bor: c}
|
||||||
// check and commit span
|
// check and commit span
|
||||||
if err := c.checkAndCommitSpan(state, header, cx); err != nil {
|
if err := c.checkAndCommitSpan(state, header, cx); err != nil {
|
||||||
|
|
@ -664,10 +664,12 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// commit statees
|
if !c.WithoutHeimdall {
|
||||||
if err := c.CommitStates(state, header, cx); err != nil {
|
// commit statees
|
||||||
log.Error("Error while committing states", "error", err)
|
if err := c.CommitStates(state, header, cx); err != nil {
|
||||||
return
|
log.Error("Error while committing states", "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -680,7 +682,7 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
|
||||||
// nor block rewards given, and returns the final block.
|
// nor block rewards given, and returns the final block.
|
||||||
func (c *Bor) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
|
func (c *Bor) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
|
||||||
headerNumber := header.Number.Uint64()
|
headerNumber := header.Number.Uint64()
|
||||||
if !c.WithoutHeimdall && headerNumber%c.config.Sprint == 0 {
|
if headerNumber%c.config.Sprint == 0 {
|
||||||
cx := chainContext{Chain: chain, Bor: c}
|
cx := chainContext{Chain: chain, Bor: c}
|
||||||
|
|
||||||
// check and commit span
|
// check and commit span
|
||||||
|
|
@ -690,10 +692,12 @@ func (c *Bor) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Hea
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// commit statees
|
if !c.WithoutHeimdall {
|
||||||
if err := c.CommitStates(state, header, cx); err != nil {
|
// commit statees
|
||||||
log.Error("Error while committing states", "error", err)
|
if err := c.CommitStates(state, header, cx); err != nil {
|
||||||
return nil, err
|
log.Error("Error while committing states", "error", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -967,15 +971,23 @@ func (c *Bor) fetchAndCommitSpan(
|
||||||
header *types.Header,
|
header *types.Header,
|
||||||
chain core.ChainContext,
|
chain core.ChainContext,
|
||||||
) error {
|
) error {
|
||||||
response, err := c.HeimdallClient.FetchWithRetry(fmt.Sprintf("bor/span/%d", newSpanID), "")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var heimdallSpan HeimdallSpan
|
var heimdallSpan HeimdallSpan
|
||||||
if err := json.Unmarshal(response.Result, &heimdallSpan); err != nil {
|
|
||||||
return err
|
if c.WithoutHeimdall {
|
||||||
|
s, err := c.getNextHeimdallSpanForTest(newSpanID, state, header, chain)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
heimdallSpan = *s
|
||||||
|
} else {
|
||||||
|
response, err := c.HeimdallClient.FetchWithRetry(fmt.Sprintf("bor/span/%d", newSpanID), "")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(response.Result, &heimdallSpan); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if chain id matches with heimdall span
|
// check if chain id matches with heimdall span
|
||||||
|
|
@ -1140,6 +1152,49 @@ func (c *Bor) SetHeimdallClient(h IHeimdallClient) {
|
||||||
// Private methods
|
// Private methods
|
||||||
//
|
//
|
||||||
|
|
||||||
|
func (c *Bor) getNextHeimdallSpanForTest(
|
||||||
|
newSpanID uint64,
|
||||||
|
state *state.StateDB,
|
||||||
|
header *types.Header,
|
||||||
|
chain core.ChainContext,
|
||||||
|
) (*HeimdallSpan, error) {
|
||||||
|
headerNumber := header.Number.Uint64()
|
||||||
|
span, err := c.GetCurrentSpan(headerNumber - 1)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// get local chain context object
|
||||||
|
localContext := chain.(chainContext)
|
||||||
|
// Retrieve the snapshot needed to verify this header and cache it
|
||||||
|
snap, err := c.snapshot(localContext.Chain, headerNumber-1, header.ParentHash, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// new span
|
||||||
|
span.ID = newSpanID
|
||||||
|
if span.EndBlock == 0 {
|
||||||
|
span.StartBlock = 256
|
||||||
|
} else {
|
||||||
|
span.StartBlock = span.EndBlock + 1
|
||||||
|
}
|
||||||
|
span.EndBlock = span.StartBlock + (100 * c.config.Sprint) - 1
|
||||||
|
|
||||||
|
selectedProducers := make([]Validator, len(snap.ValidatorSet.Validators))
|
||||||
|
for i, v := range snap.ValidatorSet.Validators {
|
||||||
|
selectedProducers[i] = *v
|
||||||
|
}
|
||||||
|
heimdallSpan := &HeimdallSpan{
|
||||||
|
Span: *span,
|
||||||
|
ValidatorSet: *snap.ValidatorSet,
|
||||||
|
SelectedProducers: selectedProducers,
|
||||||
|
ChainID: c.chainConfig.ChainID.String(),
|
||||||
|
}
|
||||||
|
|
||||||
|
return heimdallSpan, nil
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Chain context
|
// Chain context
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue