remove case after use

This commit is contained in:
Nguyen Sy Thanh Son 2019-01-03 04:15:20 +00:00
parent e526f6334a
commit a210d7ad14
2 changed files with 35 additions and 30 deletions

View file

@ -18,9 +18,9 @@ package posv
import ( import (
"bytes" "bytes"
// "strings" // "strings"
"encoding/json" "encoding/json"
// "encoding/hex" // "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -52,7 +52,7 @@ import (
const ( const (
inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory
blockSignersCacheLimit = 1800 blockSignersCacheLimit = 3600
M2ByteLength = 4 M2ByteLength = 4
) )
@ -883,13 +883,17 @@ func (c *Posv) Finalize(chain consensus.ChainReader, header *types.Header, state
} }
blkHash := s.BlockHash blkHash := s.BlockHash
*/ */
blkHash := tx.Data()[len(tx.Data())-32:] blkHash := common.BytesToHash(tx.Data()[len(tx.Data())-32:])
txHash := *tx.From()
var lAddr []common.Address
if cached, ok := c.BlockSigners.Get(blkHash); ok { if cached, ok := c.BlockSigners.Get(blkHash); ok {
lAddr := cached.([]common.Address) lAddr = cached.([]common.Address)
lAddr = append(lAddr, *tx.From()) lAddr = append(lAddr, txHash)
c.BlockSigners.Add(blkHash, lAddr) } else {
lAddr = []common.Address{txHash}
} }
c.BlockSigners.Add(blkHash, lAddr)
} }
} }

View file

@ -217,7 +217,7 @@ 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
} }
if caddrs, ok := c.GetBlockSigners().Get(blockHash); !ok { if caddrs, ok := c.BlockSigners.Get(blockHash); !ok || c.BlockSigners.Len() < 1800 {
opts := new(bind.CallOpts) opts := new(bind.CallOpts)
addrs, err := blockSigner.GetSigners(opts, blockHash) addrs, err := blockSigner.GetSigners(opts, blockHash)
if err != nil { if err != nil {
@ -226,6 +226,7 @@ func GetSignersFromContract2(c *posv.Posv, addrBlockSigner common.Address, clien
} }
return addrs, nil return addrs, nil
} else { } else {
c.BlockSigners.Remove(blockHash)
return caddrs.([]common.Address), nil return caddrs.([]common.Address), nil
} }
return nil, nil return nil, nil