mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
get blocksigner from cached
This commit is contained in:
parent
462b018622
commit
e526f6334a
2 changed files with 32 additions and 4 deletions
|
|
@ -18,7 +18,9 @@ package posv
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
// "strings"
|
||||
"encoding/json"
|
||||
// "encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
|
@ -30,6 +32,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
// "github.com/ethereum/go-ethereum/accounts/abi"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/consensus"
|
||||
|
|
@ -857,13 +860,38 @@ func (c *Posv) Finalize(chain consensus.ChainReader, header *types.Header, state
|
|||
number := header.Number.Uint64()
|
||||
rCheckpoint := chain.Config().Posv.RewardCheckpoint
|
||||
|
||||
var lAddr []common.Address
|
||||
/*
|
||||
abiJSON := `[{"inputs":[{"name":"_blockNumber","type":"uint256"},{"name":"_blockHash","type":"bytes32"}],"name":"sign","type":"function"}]`
|
||||
abiReader, err := abi.JSON(strings.NewReader(abiJSON))
|
||||
if err != nil {
|
||||
log.Error("Abi parser error", err)
|
||||
}
|
||||
|
||||
type Sign struct {
|
||||
BlockNumber *big.Int
|
||||
BlockHash common.Hash
|
||||
}
|
||||
var s Sign
|
||||
*/
|
||||
|
||||
for _, tx := range txs {
|
||||
if tx.IsSigningTransaction() {
|
||||
/*
|
||||
err = abiReader.Unpack(&s, "sign", tx.Data())
|
||||
if err != nil {
|
||||
log.Error("Abi unpack error", err)
|
||||
}
|
||||
blkHash := s.BlockHash
|
||||
*/
|
||||
blkHash := tx.Data()[len(tx.Data())-32:]
|
||||
|
||||
if cached, ok := c.BlockSigners.Get(blkHash); ok {
|
||||
lAddr := cached.([]common.Address)
|
||||
lAddr = append(lAddr, *tx.From())
|
||||
c.BlockSigners.Add(blkHash, lAddr)
|
||||
}
|
||||
}
|
||||
}
|
||||
c.BlockSigners.Add(header.Hash(), lAddr)
|
||||
|
||||
if c.HookReward != nil && number%rCheckpoint == 0 {
|
||||
err, rewards := c.HookReward(chain, state, header)
|
||||
|
|
|
|||
|
|
@ -217,8 +217,8 @@ func GetSignersFromContract2(c *posv.Posv, addrBlockSigner common.Address, clien
|
|||
log.Error("Fail get instance of blockSigner", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
opts := new(bind.CallOpts)
|
||||
if caddrs, ok := c.GetBlockSigners().Get(blockHash); !ok {
|
||||
opts := new(bind.CallOpts)
|
||||
addrs, err := blockSigner.GetSigners(opts, blockHash)
|
||||
if err != nil {
|
||||
log.Error("Fail get block signers", "error", err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue