mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-14 16:03:45 +00:00
Merge pull request #9 from maticnetwork/mat-494
MAT-494 verify block before validator set change at sprint end
This commit is contained in:
commit
d9ffa9605d
3 changed files with 19 additions and 19 deletions
|
|
@ -577,7 +577,7 @@ func (c *Bor) verifySeal(chain consensus.ChainReader, header *types.Header, pare
|
||||||
}
|
}
|
||||||
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
|
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
|
||||||
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
|
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
|
||||||
limit := len(validators) - (len(validators)/2 + 1)
|
limit := len(validators)/2 + 1
|
||||||
|
|
||||||
// temp index
|
// temp index
|
||||||
tempIndex := signerIndex
|
tempIndex := signerIndex
|
||||||
|
|
@ -761,7 +761,7 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
|
||||||
|
|
||||||
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
|
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
|
||||||
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
|
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
|
||||||
limit := len(validators) - (len(validators)/2 + 1)
|
limit := len(validators)/2 + 1
|
||||||
|
|
||||||
// temp index
|
// temp index
|
||||||
tempIndex := signerIndex
|
tempIndex := signerIndex
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,6 @@ func FetchFromHeimdallWithRetry(client http.Client, urlString string, paths ...s
|
||||||
}
|
}
|
||||||
fmt.Println("Retrying again in 5 seconds", u.String())
|
fmt.Println("Retrying again in 5 seconds", u.String())
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,12 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
lru "github.com/hashicorp/golang-lru"
|
||||||
"github.com/maticnetwork/bor/common"
|
"github.com/maticnetwork/bor/common"
|
||||||
"github.com/maticnetwork/bor/core/types"
|
"github.com/maticnetwork/bor/core/types"
|
||||||
"github.com/maticnetwork/bor/ethdb"
|
"github.com/maticnetwork/bor/ethdb"
|
||||||
"github.com/maticnetwork/bor/internal/ethapi"
|
"github.com/maticnetwork/bor/internal/ethapi"
|
||||||
"github.com/maticnetwork/bor/params"
|
"github.com/maticnetwork/bor/params"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Snapshot is the state of the authorization voting at a given point in time.
|
// Snapshot is the state of the authorization voting at a given point in time.
|
||||||
|
|
@ -150,20 +150,6 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// change validator set and change proposer
|
|
||||||
if number > 0 && (number+1)%s.config.Sprint == 0 {
|
|
||||||
validatorBytes := header.Extra[extraVanity : len(header.Extra)-extraSeal]
|
|
||||||
|
|
||||||
// get validators from headers and use that for new validator set
|
|
||||||
newVals, _ := ParseValidators(validatorBytes)
|
|
||||||
v := getUpdatedValidatorSet(snap.ValidatorSet.Copy(), newVals)
|
|
||||||
v.IncrementProposerPriority(1)
|
|
||||||
snap.ValidatorSet = v
|
|
||||||
|
|
||||||
// log new validator set
|
|
||||||
fmt.Println("Current validator set", "number", snap.Number, "validatorSet", snap.ValidatorSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if signer is in validator set
|
// check if signer is in validator set
|
||||||
if !snap.ValidatorSet.HasAddress(signer.Bytes()) {
|
if !snap.ValidatorSet.HasAddress(signer.Bytes()) {
|
||||||
return nil, errUnauthorizedSigner
|
return nil, errUnauthorizedSigner
|
||||||
|
|
@ -178,7 +164,7 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
|
||||||
proposer := snap.ValidatorSet.GetProposer().Address
|
proposer := snap.ValidatorSet.GetProposer().Address
|
||||||
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
|
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
|
||||||
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
|
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
|
||||||
limit := len(validators) - (len(validators)/2 + 1)
|
limit := len(validators)/2 + 1
|
||||||
|
|
||||||
// temp index
|
// temp index
|
||||||
tempIndex := signerIndex
|
tempIndex := signerIndex
|
||||||
|
|
@ -188,12 +174,27 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if tempIndex-proposerIndex > limit {
|
if tempIndex-proposerIndex > limit {
|
||||||
|
fmt.Println("Invalid signer: error while applying headers", "proposerIndex", validators[proposerIndex].Address.Hex(), "signerIndex", validators[signerIndex].Address.Hex())
|
||||||
return nil, errRecentlySigned
|
return nil, errRecentlySigned
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add recents
|
// add recents
|
||||||
snap.Recents[number] = signer
|
snap.Recents[number] = signer
|
||||||
|
|
||||||
|
// change validator set and change proposer
|
||||||
|
if number > 0 && (number+1)%s.config.Sprint == 0 {
|
||||||
|
validatorBytes := header.Extra[extraVanity : len(header.Extra)-extraSeal]
|
||||||
|
|
||||||
|
// get validators from headers and use that for new validator set
|
||||||
|
newVals, _ := ParseValidators(validatorBytes)
|
||||||
|
v := getUpdatedValidatorSet(snap.ValidatorSet.Copy(), newVals)
|
||||||
|
v.IncrementProposerPriority(1)
|
||||||
|
snap.ValidatorSet = v
|
||||||
|
|
||||||
|
// log new validator set
|
||||||
|
fmt.Println("New changed validator set", "number", snap.Number, "validatorSet", snap.ValidatorSet, "currentSigner", signer.Hex())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
snap.Number += uint64(len(headers))
|
snap.Number += uint64(len(headers))
|
||||||
snap.Hash = headers[len(headers)-1].Hash()
|
snap.Hash = headers[len(headers)-1].Hash()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue