mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
// "strings"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
// "encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
@ -30,6 +32,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"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"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/consensus"
|
"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()
|
number := header.Number.Uint64()
|
||||||
rCheckpoint := chain.Config().Posv.RewardCheckpoint
|
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 {
|
for _, tx := range txs {
|
||||||
if tx.IsSigningTransaction() {
|
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())
|
lAddr = append(lAddr, *tx.From())
|
||||||
|
c.BlockSigners.Add(blkHash, lAddr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.BlockSigners.Add(header.Hash(), lAddr)
|
|
||||||
|
|
||||||
if c.HookReward != nil && number%rCheckpoint == 0 {
|
if c.HookReward != nil && number%rCheckpoint == 0 {
|
||||||
err, rewards := c.HookReward(chain, state, header)
|
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)
|
log.Error("Fail get instance of blockSigner", "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
opts := new(bind.CallOpts)
|
|
||||||
if caddrs, ok := c.GetBlockSigners().Get(blockHash); !ok {
|
if caddrs, ok := c.GetBlockSigners().Get(blockHash); !ok {
|
||||||
|
opts := new(bind.CallOpts)
|
||||||
addrs, err := blockSigner.GetSigners(opts, blockHash)
|
addrs, err := blockSigner.GetSigners(opts, blockHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Fail get block signers", "error", err)
|
log.Error("Fail get block signers", "error", err)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue