mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-09 13:33:50 +00:00
fix: use hash instead of number for eth call
This commit is contained in:
parent
264551cbc1
commit
43e41773fa
2 changed files with 14 additions and 8 deletions
|
|
@ -455,7 +455,7 @@ func (c *Bor) snapshot(chain consensus.ChainHeaderReader, number uint64, hash co
|
||||||
hash := checkpoint.Hash()
|
hash := checkpoint.Hash()
|
||||||
|
|
||||||
// get validators and current span
|
// get validators and current span
|
||||||
validators, err := c.GetCurrentValidators(number, number+1)
|
validators, err := c.GetCurrentValidators(hash, number+1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -609,7 +609,7 @@ func (c *Bor) Prepare(chain consensus.ChainHeaderReader, header *types.Header) e
|
||||||
|
|
||||||
// get validator set if number
|
// get validator set if number
|
||||||
if (number+1)%c.config.Sprint == 0 {
|
if (number+1)%c.config.Sprint == 0 {
|
||||||
newValidators, err := c.GetCurrentValidators(snap.Number, number+1)
|
newValidators, err := c.GetCurrentValidators(header.ParentHash, number+1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("unknown validators")
|
return errors.New("unknown validators")
|
||||||
}
|
}
|
||||||
|
|
@ -853,6 +853,9 @@ func (c *Bor) GetCurrentSpan(headerHash common.Hash) (*Span, error) {
|
||||||
// method
|
// method
|
||||||
method := "getCurrentSpan"
|
method := "getCurrentSpan"
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
data, err := c.validatorSetABI.Pack(method)
|
data, err := c.validatorSetABI.Pack(method)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to pack tx for getCurrentSpan", "error", err)
|
log.Error("Unable to pack tx for getCurrentSpan", "error", err)
|
||||||
|
|
@ -862,7 +865,7 @@ func (c *Bor) GetCurrentSpan(headerHash common.Hash) (*Span, error) {
|
||||||
msgData := (hexutil.Bytes)(data)
|
msgData := (hexutil.Bytes)(data)
|
||||||
toAddress := common.HexToAddress(c.config.ValidatorContract)
|
toAddress := common.HexToAddress(c.config.ValidatorContract)
|
||||||
gas := (hexutil.Uint64)(uint64(math.MaxUint64 / 2))
|
gas := (hexutil.Uint64)(uint64(math.MaxUint64 / 2))
|
||||||
result, err := c.ethAPI.Call(context.Background(), ethapi.CallArgs{
|
result, err := c.ethAPI.Call(ctx, ethapi.CallArgs{
|
||||||
Gas: &gas,
|
Gas: &gas,
|
||||||
To: &toAddress,
|
To: &toAddress,
|
||||||
Data: &msgData,
|
Data: &msgData,
|
||||||
|
|
@ -892,13 +895,16 @@ func (c *Bor) GetCurrentSpan(headerHash common.Hash) (*Span, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCurrentValidators get current validators
|
// GetCurrentValidators get current validators
|
||||||
func (c *Bor) GetCurrentValidators(snapshotNumber uint64, blockNumber uint64) ([]*Validator, error) {
|
func (c *Bor) GetCurrentValidators(headerHash common.Hash, blockNumber uint64) ([]*Validator, error) {
|
||||||
// block
|
// block
|
||||||
blockNr := rpc.BlockNumber(snapshotNumber)
|
blockNr := rpc.BlockNumberOrHashWithHash(headerHash, false)
|
||||||
|
|
||||||
// method
|
// method
|
||||||
method := "getBorValidators"
|
method := "getBorValidators"
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
data, err := c.validatorSetABI.Pack(method, big.NewInt(0).SetUint64(blockNumber))
|
data, err := c.validatorSetABI.Pack(method, big.NewInt(0).SetUint64(blockNumber))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to pack tx for getValidator", "error", err)
|
log.Error("Unable to pack tx for getValidator", "error", err)
|
||||||
|
|
@ -909,11 +915,11 @@ func (c *Bor) GetCurrentValidators(snapshotNumber uint64, blockNumber uint64) ([
|
||||||
msgData := (hexutil.Bytes)(data)
|
msgData := (hexutil.Bytes)(data)
|
||||||
toAddress := common.HexToAddress(c.config.ValidatorContract)
|
toAddress := common.HexToAddress(c.config.ValidatorContract)
|
||||||
gas := (hexutil.Uint64)(uint64(math.MaxUint64 / 2))
|
gas := (hexutil.Uint64)(uint64(math.MaxUint64 / 2))
|
||||||
result, err := c.ethAPI.Call(context.Background(), ethapi.CallArgs{
|
result, err := c.ethAPI.Call(ctx, ethapi.CallArgs{
|
||||||
Gas: &gas,
|
Gas: &gas,
|
||||||
To: &toAddress,
|
To: &toAddress,
|
||||||
Data: &msgData,
|
Data: &msgData,
|
||||||
}, rpc.BlockNumberOrHash{BlockNumber: &blockNr}, nil)
|
}, blockNr, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
// return nil, err
|
// return nil, err
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ func TestInsertingSpanSizeBlocks(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.True(t, h.AssertCalled(t, "FetchWithRetry", spanPath, ""))
|
assert.True(t, h.AssertCalled(t, "FetchWithRetry", spanPath, ""))
|
||||||
validators, err := _bor.GetCurrentValidators(sprintSize, spanSize) // check validator set at the first block of new span
|
validators, err := _bor.GetCurrentValidators(block.Hash(), spanSize) // check validator set at the first block of new span
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s", err)
|
t.Fatalf("%s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue