mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
remove case after use
This commit is contained in:
parent
e526f6334a
commit
a210d7ad14
2 changed files with 35 additions and 30 deletions
|
|
@ -18,9 +18,9 @@ package posv
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
// "strings"
|
||||
// "strings"
|
||||
"encoding/json"
|
||||
// "encoding/hex"
|
||||
// "encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
|
@ -52,7 +52,7 @@ import (
|
|||
|
||||
const (
|
||||
inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory
|
||||
blockSignersCacheLimit = 1800
|
||||
blockSignersCacheLimit = 3600
|
||||
M2ByteLength = 4
|
||||
)
|
||||
|
||||
|
|
@ -860,36 +860,40 @@ func (c *Posv) Finalize(chain consensus.ChainReader, header *types.Header, state
|
|||
number := header.Number.Uint64()
|
||||
rCheckpoint := chain.Config().Posv.RewardCheckpoint
|
||||
|
||||
/*
|
||||
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)
|
||||
}
|
||||
/*
|
||||
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
|
||||
*/
|
||||
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:]
|
||||
/*
|
||||
err = abiReader.Unpack(&s, "sign", tx.Data())
|
||||
if err != nil {
|
||||
log.Error("Abi unpack error", err)
|
||||
}
|
||||
blkHash := s.BlockHash
|
||||
*/
|
||||
blkHash := common.BytesToHash(tx.Data()[len(tx.Data())-32:])
|
||||
txHash := *tx.From()
|
||||
|
||||
if cached, ok := c.BlockSigners.Get(blkHash); ok {
|
||||
lAddr := cached.([]common.Address)
|
||||
lAddr = append(lAddr, *tx.From())
|
||||
c.BlockSigners.Add(blkHash, lAddr)
|
||||
}
|
||||
var lAddr []common.Address
|
||||
if cached, ok := c.BlockSigners.Get(blkHash); ok {
|
||||
lAddr = cached.([]common.Address)
|
||||
lAddr = append(lAddr, txHash)
|
||||
} else {
|
||||
lAddr = []common.Address{txHash}
|
||||
}
|
||||
c.BlockSigners.Add(blkHash, lAddr)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
if caddrs, ok := c.GetBlockSigners().Get(blockHash); !ok {
|
||||
opts := new(bind.CallOpts)
|
||||
if caddrs, ok := c.BlockSigners.Get(blockHash); !ok || c.BlockSigners.Len() < 1800 {
|
||||
opts := new(bind.CallOpts)
|
||||
addrs, err := blockSigner.GetSigners(opts, blockHash)
|
||||
if err != nil {
|
||||
log.Error("Fail get block signers", "error", err)
|
||||
|
|
@ -226,6 +226,7 @@ func GetSignersFromContract2(c *posv.Posv, addrBlockSigner common.Address, clien
|
|||
}
|
||||
return addrs, nil
|
||||
} else {
|
||||
c.BlockSigners.Remove(blockHash)
|
||||
return caddrs.([]common.Address), nil
|
||||
}
|
||||
return nil, nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue