mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
Merge pull request #132 from olumuyiwadad/Fix_wrongList_AtSnapShot
Work around for the issue "return wrong list signers from snapshot"
This commit is contained in:
commit
fae50b18bf
8 changed files with 45 additions and 22 deletions
|
|
@ -23,6 +23,7 @@ const (
|
||||||
MergeSignRange = 15
|
MergeSignRange = 15
|
||||||
RangeReturnSigner = 150
|
RangeReturnSigner = 150
|
||||||
MinimunMinerBlockPerEpoch = 1
|
MinimunMinerBlockPerEpoch = 1
|
||||||
|
IgnoreSignerCheckBlock = uint64(27307800)
|
||||||
)
|
)
|
||||||
|
|
||||||
var TIP2019Block = big.NewInt(1)
|
var TIP2019Block = big.NewInt(1)
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,9 @@ func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) }
|
||||||
// IsHexAddress verifies whether a string can represent a valid hex-encoded
|
// IsHexAddress verifies whether a string can represent a valid hex-encoded
|
||||||
// Ethereum address or not.
|
// Ethereum address or not.
|
||||||
func IsHexAddress(s string) bool {
|
func IsHexAddress(s string) bool {
|
||||||
|
if hasXDCPrefix(s) {
|
||||||
|
s = s[3:]
|
||||||
|
}
|
||||||
if hasHexPrefix(s) {
|
if hasHexPrefix(s) {
|
||||||
s = s[2:]
|
s = s[2:]
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +199,7 @@ func (a Address) Hex() string {
|
||||||
result[i] -= 32
|
result[i] -= 32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "0x" + string(result)
|
return "xdc" + string(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements the stringer interface and is used also by the logger.
|
// String implements the stringer interface and is used also by the logger.
|
||||||
|
|
@ -230,7 +233,7 @@ func (a *Address) Set(other Address) {
|
||||||
|
|
||||||
// MarshalText returns the hex representation of a.
|
// MarshalText returns the hex representation of a.
|
||||||
func (a Address) MarshalText() ([]byte, error) {
|
func (a Address) MarshalText() ([]byte, error) {
|
||||||
return hexutil.Bytes(a[:]).MarshalText()
|
return hexutil.Bytes(a[:]).MarshalXDCText()
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalText parses a hash in hex syntax.
|
// UnmarshalText parses a hash in hex syntax.
|
||||||
|
|
|
||||||
|
|
@ -417,20 +417,11 @@ func (c *XDPoS) verifyCascadingFields(chain consensus.ChainReader, header *types
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return c.verifySeal(chain, header, parents, fullVerify)
|
return c.verifySeal(chain, header, parents, fullVerify)
|
||||||
}
|
}
|
||||||
|
signers, err = c.GetSignersFromContract(chain, header)
|
||||||
// try again the progress with signers querying from smart contract
|
|
||||||
// for example the checkpoint is 886500 -> the start gap block is 886495
|
|
||||||
startGapBlockHeader := header
|
|
||||||
for step := uint64(1); step <= chain.Config().XDPoS.Gap; step++ {
|
|
||||||
startGapBlockHeader = chain.GetHeader(startGapBlockHeader.ParentHash, number-step)
|
|
||||||
}
|
|
||||||
signers, err = c.HookGetSignersFromContract(startGapBlockHeader.Hash())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Can't get signers from Smart Contract ", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.checkSignersOnCheckpoint(chain, header, signers)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return c.verifySeal(chain, header, parents, fullVerify)
|
return c.verifySeal(chain, header, parents, fullVerify)
|
||||||
}
|
}
|
||||||
|
|
@ -440,6 +431,10 @@ func (c *XDPoS) verifyCascadingFields(chain consensus.ChainReader, header *types
|
||||||
|
|
||||||
func (c *XDPoS) checkSignersOnCheckpoint(chain consensus.ChainReader, header *types.Header, signers []common.Address) error {
|
func (c *XDPoS) checkSignersOnCheckpoint(chain consensus.ChainReader, header *types.Header, signers []common.Address) error {
|
||||||
number := header.Number.Uint64()
|
number := header.Number.Uint64()
|
||||||
|
// ignore signerCheck at checkpoint block 27307800 due to wrong snapshot at gap 27307799
|
||||||
|
if number == common.IgnoreSignerCheckBlock {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
penPenalties := []common.Address{}
|
penPenalties := []common.Address{}
|
||||||
if c.HookPenalty != nil || c.HookPenaltyTIPSigning != nil {
|
if c.HookPenalty != nil || c.HookPenaltyTIPSigning != nil {
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -1281,3 +1276,16 @@ func (c *XDPoS) CheckMNTurn(chain consensus.ChainReader, parent *types.Header, s
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *XDPoS) GetSignersFromContract(chain consensus.ChainReader, checkpointHeader *types.Header) ([]common.Address, error) {
|
||||||
|
startGapBlockHeader := checkpointHeader
|
||||||
|
number := checkpointHeader.Number.Uint64()
|
||||||
|
for step := uint64(1); step <= chain.Config().XDPoS.Gap; step++ {
|
||||||
|
startGapBlockHeader = chain.GetHeader(startGapBlockHeader.ParentHash, number-step)
|
||||||
|
}
|
||||||
|
signers, err := c.HookGetSignersFromContract(startGapBlockHeader.Hash())
|
||||||
|
if err != nil {
|
||||||
|
return []common.Address{}, fmt.Errorf("Can't get signers from Smart Contract . Err: %v", err)
|
||||||
|
}
|
||||||
|
return signers, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,17 +60,26 @@ type rewardLog struct {
|
||||||
var TxSignMu sync.RWMutex
|
var TxSignMu sync.RWMutex
|
||||||
|
|
||||||
// Send tx sign for block number to smart contract blockSigner.
|
// Send tx sign for block number to smart contract blockSigner.
|
||||||
func CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, manager *accounts.Manager, block *types.Block, chainDb ethdb.Database) error {
|
func CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, manager *accounts.Manager, block *types.Block, chainDb ethdb.Database, eb common.Address) error {
|
||||||
TxSignMu.Lock()
|
TxSignMu.Lock()
|
||||||
defer TxSignMu.Unlock()
|
defer TxSignMu.Unlock()
|
||||||
if chainConfig.XDPoS != nil {
|
if chainConfig.XDPoS != nil {
|
||||||
// Find active account.
|
// Find active account.
|
||||||
account := accounts.Account{}
|
account := accounts.Account{}
|
||||||
var wallet accounts.Wallet
|
var wallet accounts.Wallet
|
||||||
|
etherbaseAccount := accounts.Account{
|
||||||
|
Address: eb,
|
||||||
|
URL: accounts.URL{},
|
||||||
|
}
|
||||||
if wallets := manager.Wallets(); len(wallets) > 0 {
|
if wallets := manager.Wallets(); len(wallets) > 0 {
|
||||||
wallet = wallets[0]
|
if w, err := manager.Find(etherbaseAccount); err == nil && w != nil {
|
||||||
if accts := wallets[0].Accounts(); len(accts) > 0 {
|
wallet = w
|
||||||
account = accts[0]
|
account = etherbaseAccount
|
||||||
|
} else {
|
||||||
|
wallet = wallets[0]
|
||||||
|
if accts := wallets[0].Accounts(); len(accts) > 0 {
|
||||||
|
account = accts[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1271,7 +1271,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty
|
||||||
stats.processed++
|
stats.processed++
|
||||||
stats.usedGas += usedGas
|
stats.usedGas += usedGas
|
||||||
stats.report(chain, i, bc.stateCache.TrieDB().Size())
|
stats.report(chain, i, bc.stateCache.TrieDB().Size())
|
||||||
if status == CanonStatTy && bc.chainConfig.XDPoS != nil {
|
if bc.chainConfig.XDPoS != nil {
|
||||||
// epoch block
|
// epoch block
|
||||||
if (chain[i].NumberU64() % bc.chainConfig.XDPoS.Epoch) == 0 {
|
if (chain[i].NumberU64() % bc.chainConfig.XDPoS.Epoch) == 0 {
|
||||||
CheckpointCh <- 1
|
CheckpointCh <- 1
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if block.NumberU64()%common.MergeSignRange == 0 || !eth.chainConfig.IsTIP2019(block.Number()) {
|
if block.NumberU64()%common.MergeSignRange == 0 || !eth.chainConfig.IsTIP2019(block.Number()) {
|
||||||
if err := contracts.CreateTransactionSign(chainConfig, eth.txPool, eth.accountManager, block, chainDb); err != nil {
|
if err := contracts.CreateTransactionSign(chainConfig, eth.txPool, eth.accountManager, block, chainDb, eb); err != nil {
|
||||||
return fmt.Errorf("Fail to create tx sign for importing block: %v", err)
|
return fmt.Errorf("Fail to create tx sign for importing block: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -472,12 +472,14 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
sort.Slice(candidates, func(i, j int) bool {
|
sort.Slice(candidates, func(i, j int) bool {
|
||||||
return candidates[i].Stake.Cmp(candidates[j].Stake) >= 0
|
return candidates[i].Stake.Cmp(candidates[j].Stake) >= 0
|
||||||
})
|
})
|
||||||
candidates = candidates[:150]
|
if len(candidates) > 150 {
|
||||||
|
candidates = candidates[:150]
|
||||||
|
}
|
||||||
result := []common.Address{}
|
result := []common.Address{}
|
||||||
for _, candidate := range candidates {
|
for _, candidate := range candidates {
|
||||||
result = append(result, candidate.Address)
|
result = append(result, candidate.Address)
|
||||||
}
|
}
|
||||||
return result[:150], nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook calculates reward for masternodes
|
// Hook calculates reward for masternodes
|
||||||
|
|
|
||||||
|
|
@ -413,7 +413,7 @@ func (self *worker) wait() {
|
||||||
}
|
}
|
||||||
// Send tx sign to smart contract blockSigners.
|
// Send tx sign to smart contract blockSigners.
|
||||||
if block.NumberU64()%common.MergeSignRange == 0 || !self.config.IsTIP2019(block.Number()) {
|
if block.NumberU64()%common.MergeSignRange == 0 || !self.config.IsTIP2019(block.Number()) {
|
||||||
if err := contracts.CreateTransactionSign(self.config, self.eth.TxPool(), self.eth.AccountManager(), block, self.chainDb); err != nil {
|
if err := contracts.CreateTransactionSign(self.config, self.eth.TxPool(), self.eth.AccountManager(), block, self.chainDb, self.coinbase); err != nil {
|
||||||
log.Error("Fail to create tx sign for signer", "error", "err")
|
log.Error("Fail to create tx sign for signer", "error", "err")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VersionMajor = 1 // Major version component of the current release
|
VersionMajor = 1 // Major version component of the current release
|
||||||
VersionMinor = 0 // Minor version component of the current release
|
VersionMinor = 1 // Minor version component of the current release
|
||||||
VersionPatch = 1 // Patch version component of the current release
|
VersionPatch = 1 // Patch version component of the current release
|
||||||
VersionMeta = "stable" // Version metadata to append to the version string
|
VersionMeta = "stable" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue