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

@ -52,7 +52,7 @@ import (
const (
inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory
blockSignersCacheLimit = 1800
blockSignersCacheLimit = 3600
M2ByteLength = 4
)
@ -883,13 +883,17 @@ func (c *Posv) Finalize(chain consensus.ChainReader, header *types.Header, state
}
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 {
lAddr := cached.([]common.Address)
lAddr = append(lAddr, *tx.From())
c.BlockSigners.Add(blkHash, lAddr)
lAddr = cached.([]common.Address)
lAddr = append(lAddr, txHash)
} 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)
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)
addrs, err := blockSigner.GetSigners(opts, blockHash)
if err != nil {
@ -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