Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
problem: chainid should be allowed to be 0 (zero-value), but not nil
Browse files Browse the repository at this point in the history
solution: don't check against 0 in ChainConfig.GetChainID uses and simplify ChainIdSigner.Equal
  • Loading branch information
whilei committed May 10, 2017
1 parent 334ec29 commit 3cd9c82
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 22 deletions.
9 changes: 8 additions & 1 deletion core/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,19 @@ func TestChainConfig_GetSigner(t *testing.T) {
func TestChainConfig_GetChainID(t *testing.T) {
d := DefaultConfig
cid := d.GetChainID()
// check is not zero
if cid.Cmp(new(big.Int)) == 0 {
t.Errorf("got: %v, want: %v", cid, DefaultChainConfigChainID)
}
// check is expected default 61
if cid.Cmp(DefaultChainConfigChainID) != 0 {
t.Errorf("got: %v, want: %v", cid, DefaultChainConfigChainID)
}

d = &ChainConfig{} // no chain id feature
// no chain id feature configured, should return zero-value (0)
d = &ChainConfig{}
cid = d.GetChainID()
// check is zero
if cid.Cmp(new(big.Int)) != 0 {
t.Errorf("got: %v, want: %v", cid, new(big.Int))
}
Expand Down
7 changes: 1 addition & 6 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ var (
ErrIntrinsicGas = errors.New("Intrinsic gas too low")
ErrGasLimit = errors.New("Exceeds block gas limit")
ErrNegativeValue = errors.New("Negative value")
ErrChainID = errors.New("Invalid (zero-value) chain id")
)

const (
Expand Down Expand Up @@ -79,13 +78,9 @@ type TxPool struct {
}

func NewTxPool(config *ChainConfig, eventMux *event.TypeMux, currentStateFn stateFn, gasLimitFn func() *big.Int) *TxPool {
chainid := config.GetChainID()
if chainid.Cmp(new(big.Int)) == 0 {
panic(ErrChainID)
}
pool := &TxPool{
config: config,
signer: types.NewChainIdSigner(chainid),
signer: types.NewChainIdSigner(config.GetChainID()),
pending: make(map[common.Hash]*types.Transaction),
queue: make(map[common.Address]map[common.Hash]*types.Transaction),
eventMux: eventMux,
Expand Down
5 changes: 1 addition & 4 deletions core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ func (s ChainIdSigner) Equal(s2 Signer) bool {
if !ok {
return false
}
if other.chainId.Cmp(new(big.Int)) == 0 || other.chainId == nil {
return false
}
if s.chainId.Cmp(new(big.Int)) == 0 || s.chainId == nil {
if other.chainId == nil || s.chainId == nil {
return false
}

Expand Down
6 changes: 1 addition & 5 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,11 +825,7 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
if fullTx {
formatTx = func(tx *types.Transaction) (interface{}, error) {
if tx.Protected() {
chainid := s.bc.Config().GetChainID()
if chainid.Cmp(new(big.Int)) == 0 {
return nil, errors.New("invalid chain configuration: chainid is zero-value")
}
tx.SetSigner(types.NewChainIdSigner(chainid))
tx.SetSigner(types.NewChainIdSigner(s.bc.Config().GetChainID()))
}
return newRPCTransaction(b, tx.Hash())
}
Expand Down
7 changes: 1 addition & 6 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"sync/atomic"
"time"

"errors"
"github.com/ethereumproject/go-ethereum/accounts"
"github.com/ethereumproject/go-ethereum/common"
"github.com/ethereumproject/go-ethereum/core"
Expand Down Expand Up @@ -357,13 +356,9 @@ func (self *worker) makeCurrent(parent *types.Block, header *types.Header) error
if err != nil {
return err
}
chainid := self.config.GetChainID()
if chainid.Cmp(new(big.Int)) == 0 {
return errors.New("invalid chain configuration: chainid is zero-value")
}
work := &Work{
config: self.config,
signer: types.NewChainIdSigner(chainid),
signer: types.NewChainIdSigner(self.config.GetChainID()),
state: state,
ancestors: set.New(),
family: set.New(),
Expand Down

0 comments on commit 3cd9c82

Please sign in to comment.