Merge branch 'master' of github.com:harmony-one/harmony into rj_branch

pull/112/head
Rongjian Lan 6 years ago
commit a1b4bdfd3a
  1. 4
      core/blockchain.go
  2. 6
      core/chain_makers.go
  3. 3
      core/events.go
  4. 3
      core/genesis.go
  5. 4
      core/headerchain.go
  6. 2
      core/state_transition.go
  7. 1
      core/tx_pool.go
  8. 8
      core/tx_pool_test.go
  9. 38
      core/types/block.go
  10. 7
      core/types/bloom9.go
  11. 2
      core/types/derive_sha.go
  12. 112
      core/types/transaction.go
  13. 48
      core/types/transaction_signing.go
  14. 16
      core/types/transaction_signing_test.go
  15. 4
      core/types/transaction_test.go
  16. 5
      core/vm/logger_test.go
  17. 1
      core/vm/runtime/env.go
  18. 11
      core/vm/runtime/runtime_test.go
  19. 2
      node/node.go

@ -48,8 +48,10 @@ import (
)
var (
// blockInsertTimer
blockInsertTimer = metrics.NewRegisteredTimer("chain/inserts", nil)
// ErrNoGenesis is the error when there is no genesis.
ErrNoGenesis = errors.New("Genesis not found in chain")
)
@ -189,6 +191,7 @@ func NewBlockChain(db hdb.Database, cacheConfig *CacheConfig, chainConfig *param
return bc, nil
}
// ValidateNewBlock validates new block.
func (bc *BlockChain) ValidateNewBlock(block *types.Block, address common.Address) error {
state, err := state.New(bc.CurrentBlock().Root(), bc.stateCache)
@ -734,6 +737,7 @@ func (bc *BlockChain) procFutureBlocks() {
// WriteStatus status of write
type WriteStatus byte
// Constants for WriteStatus
const (
NonStatTy WriteStatus = iota
CanonStatTy

@ -71,9 +71,9 @@ func (b *BlockGen) SetNonce(nonce types.BlockNonce) {
b.header.Nonce = nonce
}
// SetShardID sets the shardId field of the generated block.
func (b *BlockGen) SetShardID(shardId types.ShardID) {
b.header.ShardID = shardId
// SetShardID sets the shardID field of the generated block.
func (b *BlockGen) SetShardID(shardID types.ShardID) {
b.header.ShardID = shardID
}
// AddTx adds a transaction to the generated block. If no coinbase has

@ -35,14 +35,17 @@ type NewMinedBlockEvent struct{ Block *types.Block }
// RemovedLogsEvent is posted when a reorg happens
type RemovedLogsEvent struct{ Logs []*types.Log }
// ChainEvent is the struct of chain event.
type ChainEvent struct {
Block *types.Block
Hash common.Hash
Logs []*types.Log
}
// ChainSideEvent is chain side event.
type ChainSideEvent struct {
Block *types.Block
}
// ChainHeadEvent is the struct of chain head event.
type ChainHeadEvent struct{ Block *types.Block }

@ -45,7 +45,7 @@ var errGenesisNoConfig = errors.New("genesis has no chain configuration")
type Genesis struct {
Config *params.ChainConfig `json:"config"`
Nonce uint64 `json:"nonce"`
ShardID uint32 `json:"shardId"`
ShardID uint32 `json:"shardID"`
Timestamp uint64 `json:"timestamp"`
ExtraData []byte `json:"extraData"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
@ -64,6 +64,7 @@ type Genesis struct {
// GenesisAlloc specifies the initial state that is part of the genesis block.
type GenesisAlloc map[common.Address]GenesisAccount
// UnmarshalJSON is to deserialize the data into GenesisAlloc.
func (ga *GenesisAlloc) UnmarshalJSON(data []byte) error {
m := make(map[common.UnprefixedAddress]GenesisAccount)
if err := json.Unmarshal(data, &m); err != nil {

@ -204,6 +204,7 @@ func (hc *HeaderChain) WriteHeader(header *types.Header) (status WriteStatus, er
// header writes should be protected by the parent chain mutex individually.
type WhCallback func(*types.Header) error
// ValidateHeaderChain validates header chain.
func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, checkFreq int) (int, error) {
// Do a sanity check that the provided chain is actually ordered and linked
for i := 1; i < len(chain); i++ {
@ -330,9 +331,8 @@ func (hc *HeaderChain) GetAncestor(hash common.Hash, number, ancestor uint64, ma
// in this case it is cheaper to just read the header
if header := hc.GetHeader(hash, number); header != nil {
return header.ParentHash, number - 1
} else {
return common.Hash{}, 0
}
return common.Hash{}, 0
}
for ancestor != 0 {
if rawdb.ReadCanonicalHash(hc.chainDb, number) == hash {

@ -33,7 +33,7 @@ var (
)
/*
The State Transitioning Model
StateTransition is the State Transitioning Model which is described as follows:
A state transition is a change made when a transaction is applied to the current world state
The state transitioning model does all the necessary work to work out a valid new state root.

@ -104,6 +104,7 @@ var (
// TxStatus is the current status of a transaction as seen by the pool.
type TxStatus uint
// Constants for TxStatus.
const (
TxStatusUnknown TxStatus = iota
TxStatusQueued

@ -1053,13 +1053,13 @@ func TestTransactionPoolRepricingKeepsLocals(t *testing.T) {
// Create transaction (both pending and queued) with a linearly growing gasprice
for i := uint64(0); i < 500; i++ {
// Add pending
p_tx := pricedTransaction(i, 100000, big.NewInt(int64(i)), keys[2])
if err := pool.AddLocal(p_tx); err != nil {
pTx := pricedTransaction(i, 100000, big.NewInt(int64(i)), keys[2])
if err := pool.AddLocal(pTx); err != nil {
t.Fatal(err)
}
// Add queued
q_tx := pricedTransaction(i+501, 100000, big.NewInt(int64(i)), keys[2])
if err := pool.AddLocal(q_tx); err != nil {
qTx := pricedTransaction(i+501, 100000, big.NewInt(int64(i)), keys[2])
if err := pool.AddLocal(qTx); err != nil {
t.Fatal(err)
}
}

@ -75,8 +75,6 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
return hexutil.UnmarshalFixedText("BlockNonce", input, n[:])
}
//go:generate gencodec -type Header -field-override headerMarshaling -out gen_header_json.go
// Header represents a block header in the Ethereum blockchain.
type Header struct {
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
@ -93,7 +91,7 @@ type Header struct {
Extra []byte `json:"extraData" gencodec:"required"`
MixDigest common.Hash `json:"mixHash" gencodec:"required"`
Nonce BlockNonce `json:"nonce" gencodec:"required"`
ShardID ShardID `json:"shardId" gencodec:"required"`
ShardID ShardID `json:"shardID" gencodec:"required"`
}
// field type overrides for gencodec
@ -302,7 +300,7 @@ func (b *Block) GasUsed() uint64 { return b.header.GasUsed }
// Difficulty is the header difficulty.
func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) }
// TIme is header time.
// Time is header time.
func (b *Block) Time() *big.Int { return new(big.Int).Set(b.header.Time) }
// NumberU64 is the header number in uint64.
@ -316,14 +314,29 @@ func (b *Block) Nonce() uint64 { return binary.BigEndian.Uint64(b.header.Nonce[:
// ShardID is the header ShardID
func (b *Block) ShardID() uint32 { return binary.BigEndian.Uint32(b.header.ShardID[:]) }
// Bloom returns header bloom.
func (b *Block) Bloom() Bloom { return b.header.Bloom }
// Coinbase returns header coinbase.
func (b *Block) Coinbase() common.Address { return b.header.Coinbase }
// Root returns header root.
func (b *Block) Root() common.Hash { return b.header.Root }
// ParentHash return header parent hash.
func (b *Block) ParentHash() common.Hash { return b.header.ParentHash }
// TxHash returns header tx hash.
func (b *Block) TxHash() common.Hash { return b.header.TxHash }
// ReceiptHash returns header receipt hash.
func (b *Block) ReceiptHash() common.Hash { return b.header.ReceiptHash }
// Extra returns header extra.
func (b *Block) Extra() []byte { return common.CopyBytes(b.header.Extra) }
// Header returns a copy of Header.
func (b *Block) Header() *Header { return CopyHeader(b.header) }
// Body returns the non-header content of the block.
@ -348,6 +361,7 @@ func (c *writeCounter) Write(b []byte) (int, error) {
return len(b), nil
}
// CalcUncleHash returns rlp hash of uncles.
func CalcUncleHash(uncles []*Header) common.Hash {
return rlpHash(uncles)
}
@ -410,15 +424,21 @@ type blockSorter struct {
}
// Len returns len of the blocks.
func (self blockSorter) Len() int { return len(self.blocks) }
func (s blockSorter) Len() int {
return len(s.blocks)
}
// Swap swaps block i and block j.
func (self blockSorter) Swap(i, j int) {
self.blocks[i], self.blocks[j] = self.blocks[j], self.blocks[i]
func (s blockSorter) Swap(i, j int) {
s.blocks[i], s.blocks[j] = s.blocks[j], s.blocks[i]
}
// Less checks if block i is less than block j.
func (self blockSorter) Less(i, j int) bool { return self.by(self.blocks[i], self.blocks[j]) }
func (s blockSorter) Less(i, j int) bool {
return s.by(s.blocks[i], s.blocks[j])
}
// Number checks if block b1 is less than block b2.
func Number(b1, b2 *Block) bool { return b1.header.Number.Cmp(b2.header.Number) < 0 }
func Number(b1, b2 *Block) bool {
return b1.header.Number.Cmp(b2.header.Number) < 0
}

@ -68,14 +68,17 @@ func (b Bloom) Big() *big.Int {
return new(big.Int).SetBytes(b[:])
}
// Bytes returns bytes of Bloom.
func (b Bloom) Bytes() []byte {
return b[:]
}
// Test tests if an input may belong to the bloom.
func (b Bloom) Test(test *big.Int) bool {
return BloomLookup(b, test)
}
// TestBytes tests if the input represented by test []byte may belong to the bloom.
func (b Bloom) TestBytes(test []byte) bool {
return b.Test(new(big.Int).SetBytes(test))
@ -91,6 +94,7 @@ func (b *Bloom) UnmarshalText(input []byte) error {
return hexutil.UnmarshalFixedText("Bloom", input, b[:])
}
// CreateBloom creates a Bloom given the receipts.
func CreateBloom(receipts Receipts) Bloom {
bin := new(big.Int)
for _, receipt := range receipts {
@ -100,6 +104,7 @@ func CreateBloom(receipts Receipts) Bloom {
return BytesToBloom(bin.Bytes())
}
// LogsBloom ...
func LogsBloom(logs []*Log) *big.Int {
bin := new(big.Int)
for _, log := range logs {
@ -126,8 +131,10 @@ func bloom9(b []byte) *big.Int {
return r
}
// Bloom9 type.
var Bloom9 = bloom9
// BloomLookup checks if a topic may belong to the Bloom.
func BloomLookup(bin Bloom, topic bytesBacked) bool {
bloom := bin.Big()
cmp := bloom9(topic.Bytes())

@ -24,11 +24,13 @@ import (
"github.com/ethereum/go-ethereum/trie"
)
// DerivableList is the interface of DerivableList.
type DerivableList interface {
Len() int
GetRlp(i int) []byte
}
// DeriveSha calculates the hash of the trie generated by DerivableList.
func DeriveSha(list DerivableList) common.Hash {
keybuf := new(bytes.Buffer)
trie := new(trie.Trie)

@ -31,10 +31,12 @@ import (
//go:generate gencodec -type txdata -field-override txdataMarshaling -out gen_tx_json.go
// Errors constants for Transaction.
var (
ErrInvalidSig = errors.New("invalid transaction v, r, s values")
)
// Transaction struct.
type Transaction struct {
data txdata
// caches
@ -45,7 +47,7 @@ type Transaction struct {
type txdata struct {
AccountNonce uint64 `json:"nonce" gencodec:"required"`
ShardID uint32 `json:"shardId" gencodec:"required"`
ShardID uint32 `json:"shardID" gencodec:"required"`
Price *big.Int `json:"gasPrice" gencodec:"required"`
GasLimit uint64 `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" rlp:"nil"` // nil means contract creation
@ -72,22 +74,24 @@ type txdataMarshaling struct {
S *hexutil.Big
}
func NewTransaction(nonce uint64, to common.Address, shardId uint32, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction {
return newTransaction(nonce, &to, shardId, amount, gasLimit, gasPrice, data)
// NewTransaction returns new transaction.
func NewTransaction(nonce uint64, to common.Address, shardID uint32, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction {
return newTransaction(nonce, &to, shardID, amount, gasLimit, gasPrice, data)
}
func NewContractCreation(nonce uint64, shardId uint32, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction {
return newTransaction(nonce, nil, shardId, amount, gasLimit, gasPrice, data)
// NewContractCreation returns contract transaction.
func NewContractCreation(nonce uint64, shardID uint32, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction {
return newTransaction(nonce, nil, shardID, amount, gasLimit, gasPrice, data)
}
func newTransaction(nonce uint64, to *common.Address, shardId uint32, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction {
func newTransaction(nonce uint64, to *common.Address, shardID uint32, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction {
if len(data) > 0 {
data = common.CopyBytes(data)
}
d := txdata{
AccountNonce: nonce,
Recipient: to,
ShardID: shardId,
ShardID: shardID,
Payload: data,
Amount: new(big.Int),
GasLimit: gasLimit,
@ -106,9 +110,9 @@ func newTransaction(nonce uint64, to *common.Address, shardId uint32, amount *bi
return &Transaction{data: d}
}
// ChainId returns which chain id this transaction was signed for (if at all)
func (tx *Transaction) ChainId() *big.Int {
return deriveChainId(tx.data.V)
// ChainID returns which chain id this transaction was signed for (if at all)
func (tx *Transaction) ChainID() *big.Int {
return deriveChainID(tx.data.V)
}
// Protected returns whether the transaction is protected from replay protection.
@ -160,7 +164,7 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
if withSignature {
var V byte
if isProtectedV(dec.V) {
chainID := deriveChainId(dec.V).Uint64()
chainID := deriveChainID(dec.V).Uint64()
V = byte(dec.V.Uint64() - 35 - 2*chainID)
} else {
V = byte(dec.V.Uint64() - 27)
@ -174,12 +178,35 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
return nil
}
func (tx *Transaction) Data() []byte { return common.CopyBytes(tx.data.Payload) }
func (tx *Transaction) Gas() uint64 { return tx.data.GasLimit }
func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.data.Price) }
func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.data.Amount) }
func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce }
func (tx *Transaction) CheckNonce() bool { return true }
// Data returns data payload of Transaction.
func (tx *Transaction) Data() []byte {
return common.CopyBytes(tx.data.Payload)
}
// Gas returns gas of Transaction.
func (tx *Transaction) Gas() uint64 {
return tx.data.GasLimit
}
// GasPrice returns gas price of Transaction.
func (tx *Transaction) GasPrice() *big.Int {
return new(big.Int).Set(tx.data.Price)
}
// Value returns data payload of Transaction.
func (tx *Transaction) Value() *big.Int {
return new(big.Int).Set(tx.data.Amount)
}
// Nonce returns account nonce from Transaction.
func (tx *Transaction) Nonce() uint64 {
return tx.data.AccountNonce
}
// CheckNonce returns check nonce from Transaction.
func (tx *Transaction) CheckNonce() bool {
return true
}
// To returns the recipient address of the transaction.
// It returns nil if the transaction is a contract creation.
@ -254,6 +281,7 @@ func (tx *Transaction) Cost() *big.Int {
return total
}
// RawSignatureValues return raw signature values.
func (tx *Transaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int) {
return tx.data.V, tx.data.R, tx.data.S
}
@ -308,10 +336,12 @@ func (s TxByPrice) Len() int { return len(s) }
func (s TxByPrice) Less(i, j int) bool { return s[i].data.Price.Cmp(s[j].data.Price) > 0 }
func (s TxByPrice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
// Push pushes a transaction.
func (s *TxByPrice) Push(x interface{}) {
*s = append(*s, x.(*Transaction))
}
// Pop pops a transaction.
func (s *TxByPrice) Pop() interface{} {
old := *s
n := len(old)
@ -396,6 +426,7 @@ type Message struct {
checkNonce bool
}
// NewMessage returns new message.
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool) Message {
return Message{
from: from,
@ -409,11 +440,42 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
}
}
func (m Message) From() common.Address { return m.from }
func (m Message) To() *common.Address { return m.to }
func (m Message) GasPrice() *big.Int { return m.gasPrice }
func (m Message) Value() *big.Int { return m.amount }
func (m Message) Gas() uint64 { return m.gasLimit }
func (m Message) Nonce() uint64 { return m.nonce }
func (m Message) Data() []byte { return m.data }
func (m Message) CheckNonce() bool { return m.checkNonce }
// From returns from address from Message.
func (m Message) From() common.Address {
return m.from
}
// To returns to address from Message.
func (m Message) To() *common.Address {
return m.to
}
// GasPrice returns gas price from Message.
func (m Message) GasPrice() *big.Int {
return m.gasPrice
}
// Value returns the value amount from Message.
func (m Message) Value() *big.Int {
return m.amount
}
// Gas returns gas limit of the Message.
func (m Message) Gas() uint64 {
return m.gasLimit
}
// Nonce returns Nonce of the Message.
func (m Message) Nonce() uint64 {
return m.nonce
}
// Data return data of the Message.
func (m Message) Data() []byte {
return m.data
}
// CheckNonce returns checkNonce of Message.
func (m Message) CheckNonce() bool {
return m.checkNonce
}

@ -29,7 +29,7 @@ import (
// Constants for transaction signing.
var (
ErrInvalidChainId = errors.New("invalid chain id for signer")
ErrInvalidChainID = errors.New("invalid chain id for signer")
)
// sigCache is used to cache the derived sender and contains
@ -103,36 +103,39 @@ type Signer interface {
Equal(Signer) bool
}
// EIP155Transaction implements Signer using the EIP155 rules.
// EIP155Signer implements Signer using the EIP155 rules.
type EIP155Signer struct {
chainId, chainIdMul *big.Int
chainID, chainIDMul *big.Int
}
func NewEIP155Signer(chainId *big.Int) EIP155Signer {
if chainId == nil {
chainId = new(big.Int)
// NewEIP155Signer creates a EIP155Signer given chainID.
func NewEIP155Signer(chainID *big.Int) EIP155Signer {
if chainID == nil {
chainID = new(big.Int)
}
return EIP155Signer{
chainId: chainId,
chainIdMul: new(big.Int).Mul(chainId, big.NewInt(2)),
chainID: chainID,
chainIDMul: new(big.Int).Mul(chainID, big.NewInt(2)),
}
}
// Equal checks if the given EIP155Signer is equal to another Signer.
func (s EIP155Signer) Equal(s2 Signer) bool {
eip155, ok := s2.(EIP155Signer)
return ok && eip155.chainId.Cmp(s.chainId) == 0
return ok && eip155.chainID.Cmp(s.chainID) == 0
}
var big8 = big.NewInt(8)
// Sender returns the sender address of the given signer.
func (s EIP155Signer) Sender(tx *Transaction) (common.Address, error) {
if !tx.Protected() {
return HomesteadSigner{}.Sender(tx)
}
if tx.ChainId().Cmp(s.chainId) != 0 {
return common.Address{}, ErrInvalidChainId
if tx.ChainID().Cmp(s.chainID) != 0 {
return common.Address{}, ErrInvalidChainID
}
V := new(big.Int).Sub(tx.data.V, s.chainIdMul)
V := new(big.Int).Sub(tx.data.V, s.chainIDMul)
V.Sub(V, big8)
return recoverPlain(s.Hash(tx), tx.data.R, tx.data.S, V, true)
}
@ -144,9 +147,9 @@ func (s EIP155Signer) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big
if err != nil {
return nil, nil, nil, err
}
if s.chainId.Sign() != 0 {
if s.chainID.Sign() != 0 {
V = big.NewInt(int64(sig[64] + 35))
V.Add(V, s.chainIdMul)
V.Add(V, s.chainIDMul)
}
return R, S, V, nil
}
@ -161,15 +164,16 @@ func (s EIP155Signer) Hash(tx *Transaction) common.Hash {
tx.data.Recipient,
tx.data.Amount,
tx.data.Payload,
s.chainId, uint(0), uint(0),
s.chainID, uint(0), uint(0),
})
}
// HomesteadTransaction implements TransactionInterface using the
// HomesteadSigner implements TransactionInterface using the
// homestead rules.
type HomesteadSigner struct{ FrontierSigner }
func (s HomesteadSigner) Equal(s2 Signer) bool {
// Equal checks if it is equal to s2 signer.
func (hs HomesteadSigner) Equal(s2 Signer) bool {
_, ok := s2.(HomesteadSigner)
return ok
}
@ -180,13 +184,16 @@ func (hs HomesteadSigner) SignatureValues(tx *Transaction, sig []byte) (r, s, v
return hs.FrontierSigner.SignatureValues(tx, sig)
}
// Sender returns the address of the sender.
func (hs HomesteadSigner) Sender(tx *Transaction) (common.Address, error) {
return recoverPlain(hs.Hash(tx), tx.data.R, tx.data.S, tx.data.V, true)
}
// FrontierSigner ...
type FrontierSigner struct{}
func (s FrontierSigner) Equal(s2 Signer) bool {
// Equal checks if the s2 signer is equal to the given signer.
func (fs FrontierSigner) Equal(s2 Signer) bool {
_, ok := s2.(FrontierSigner)
return ok
}
@ -216,6 +223,7 @@ func (fs FrontierSigner) Hash(tx *Transaction) common.Hash {
})
}
// Sender returns the sender address of the given transaction.
func (fs FrontierSigner) Sender(tx *Transaction) (common.Address, error) {
return recoverPlain(fs.Hash(tx), tx.data.R, tx.data.S, tx.data.V, false)
}
@ -247,8 +255,8 @@ func recoverPlain(sighash common.Hash, R, S, Vb *big.Int, homestead bool) (commo
return addr, nil
}
// deriveChainId derives the chain id from the given v parameter
func deriveChainId(v *big.Int) *big.Int {
// deriveChainID derives the chain id from the given v parameter
func deriveChainID(v *big.Int) *big.Int {
if v.BitLen() <= 64 {
v := v.Uint64()
if v == 27 || v == 28 {

@ -43,7 +43,7 @@ func TestEIP155Signing(t *testing.T) {
}
}
func TestEIP155ChainId(t *testing.T) {
func TestEIP155ChainID(t *testing.T) {
key, _ := crypto.GenerateKey()
addr := crypto.PubkeyToAddress(key.PublicKey)
@ -56,8 +56,8 @@ func TestEIP155ChainId(t *testing.T) {
t.Fatal("expected tx to be protected")
}
if tx.ChainId().Cmp(signer.chainId) != 0 {
t.Error("expected chainId to be", signer.chainId, "got", tx.ChainId())
if tx.ChainID().Cmp(signer.chainID) != 0 {
t.Error("expected chainID to be", signer.chainID, "got", tx.ChainID())
}
tx = NewTransaction(0, addr, 0, new(big.Int), 0, new(big.Int), nil)
@ -70,12 +70,12 @@ func TestEIP155ChainId(t *testing.T) {
t.Error("didn't expect tx to be protected")
}
if tx.ChainId().Sign() != 0 {
t.Error("expected chain id to be 0 got", tx.ChainId())
if tx.ChainID().Sign() != 0 {
t.Error("expected chain id to be 0 got", tx.ChainID())
}
}
func TestChainId(t *testing.T) {
func TestChainID(t *testing.T) {
key, _ := defaultTestKey()
tx := NewTransaction(0, common.Address{}, 0, new(big.Int), 0, new(big.Int), nil)
@ -87,8 +87,8 @@ func TestChainId(t *testing.T) {
}
_, err = Sender(NewEIP155Signer(big.NewInt(2)), tx)
if err != ErrInvalidChainId {
t.Error("expected error:", ErrInvalidChainId)
if err != ErrInvalidChainID {
t.Error("expected error:", ErrInvalidChainID)
}
_, err = Sender(NewEIP155Signer(big.NewInt(1)), tx)

@ -172,8 +172,8 @@ func TestTransactionJSON(t *testing.T) {
if tx.Hash() != parsedTx.Hash() {
t.Errorf("parsed tx differs from original tx, want %v, got %v", tx, parsedTx)
}
if tx.ChainId().Cmp(parsedTx.ChainId()) != 0 {
t.Errorf("invalid chain id, want %d, got %d", tx.ChainId(), parsedTx.ChainId())
if tx.ChainID().Cmp(parsedTx.ChainID()) != 0 {
t.Errorf("invalid chain id, want %d, got %d", tx.ChainID(), parsedTx.ChainID())
}
}
}

@ -46,7 +46,10 @@ type dummyStatedb struct {
state.StateDB
}
func (dummyStatedb) GetRefund() uint64 { return 1337 }
// GetRefund ...
func (*dummyStatedb) GetRefund() uint64 {
return 1337
}
func TestStoreCapture(t *testing.T) {
var (

@ -22,6 +22,7 @@ import (
"github.com/harmony-one/harmony/core/vm"
)
// NewEnv returns new EVM.
func NewEnv(cfg *Config) *vm.EVM {
context := vm.Context{
CanTransfer: core.CanTransfer,

@ -149,7 +149,8 @@ func BenchmarkCall(b *testing.B) {
}
}
}
func benchmarkEVM_Create(bench *testing.B, code string) {
func benchmarkEVMCreate(bench *testing.B, code string) {
var (
statedb, _ = state.New(common.Hash{}, state.NewDatabase(db.NewMemDatabase()))
sender = common.BytesToAddress([]byte("sender"))
@ -189,17 +190,17 @@ func benchmarkEVM_Create(bench *testing.B, code string) {
func BenchmarkEVM_CREATE_500(bench *testing.B) {
// initcode size 500K, repeatedly calls CREATE and then modifies the mem contents
benchmarkEVM_Create(bench, "5b6207a120600080f0600152600056")
benchmarkEVMCreate(bench, "5b6207a120600080f0600152600056")
}
func BenchmarkEVM_CREATE2_500(bench *testing.B) {
// initcode size 500K, repeatedly calls CREATE2 and then modifies the mem contents
benchmarkEVM_Create(bench, "5b586207a120600080f5600152600056")
benchmarkEVMCreate(bench, "5b586207a120600080f5600152600056")
}
func BenchmarkEVM_CREATE_1200(bench *testing.B) {
// initcode size 1200K, repeatedly calls CREATE and then modifies the mem contents
benchmarkEVM_Create(bench, "5b62124f80600080f0600152600056")
benchmarkEVMCreate(bench, "5b62124f80600080f0600152600056")
}
func BenchmarkEVM_CREATE2_1200(bench *testing.B) {
// initcode size 1200K, repeatedly calls CREATE2 and then modifies the mem contents
benchmarkEVM_Create(bench, "5b5862124f80600080f5600152600056")
benchmarkEVMCreate(bench, "5b5862124f80600080f5600152600056")
}

@ -297,7 +297,7 @@ func New(consensus *bft.Consensus, db *hdb.LDBDatabase, selfPeer p2p.Peer) *Node
database := hdb.NewMemDatabase()
chainConfig := params.TestChainConfig
chainConfig.ChainID = big.NewInt(int64(node.Consensus.ShardID)) // Use ChainId as piggybacked ShardID
chainConfig.ChainID = big.NewInt(int64(node.Consensus.ShardID)) // Use ChainID as piggybacked ShardID
gspec := core.Genesis{
Config: chainConfig,
Alloc: genesisAloc,

Loading…
Cancel
Save