From 1afaa5f89e705534d0d4bc8ed4bd5df730de9e2b Mon Sep 17 00:00:00 2001 From: Nguyen Ba Tam Date: Tue, 23 Oct 2018 17:33:40 +0700 Subject: [PATCH] move from SubscribeTx to Subscribe Special Tx in Double Validate --- core/genesis.go | 2 +- core/tx_pool.go | 2 +- eth/backend.go | 9 ++++++--- eth/downloader/api.go | 4 ++-- eth/handler_test.go | 8 ++++---- p2p/dial.go | 2 +- swarm/api/http/error.go | 2 +- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 9d8eb27953..c87460b908 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -366,7 +366,7 @@ func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis { common.BytesToAddress([]byte{6}): {Balance: big.NewInt(1)}, // ECAdd common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing - faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}, + faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}, }, } } diff --git a/core/tx_pool.go b/core/tx_pool.go index e20aff5500..b07a924beb 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -81,7 +81,7 @@ var ( ErrZeroGasPrice = errors.New("zero gas price") - ErrDuplicateSpecialTransaction = errors.New("duplicate a specail transaction") + ErrDuplicateSpecialTransaction = errors.New("duplicate a special transaction") ) var ( diff --git a/eth/backend.go b/eth/backend.go index 4bea8f2d15..8213bf66fc 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -192,6 +192,9 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { // Hook double validation doubleValidateHook := func(block *types.Block) error { parentBlk := eth.blockchain.GetBlockByHash(block.ParentHash()) + if parentBlk == nil { + return fmt.Errorf("Fail to get parent block for hash: %v", block.ParentHash()) + } snap, err := c.GetSnapshot(eth.blockchain, parentBlk.Header()) if err != nil { if err == consensus.ErrUnknownAncestor { @@ -205,6 +208,9 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { return fmt.Errorf("Fail to validate M2 condition for importing block: %v", err) } if eth.etherbase != m2 { + txCh := make(chan core.TxPreEvent, txChanSize) + subEvent := eth.txPool.SubscribeSpecialTxPreEvent(txCh) + defer subEvent.Unsubscribe() // firstly, look into pending txPool pendingMap, err := eth.txPool.Pending() if err != nil { @@ -221,8 +227,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { } } //then wait until signTx from m2 comes into txPool - txCh := make(chan core.TxPreEvent, txChanSize) - subEvent := eth.txPool.SubscribeTxPreEvent(txCh) select { case event := <-txCh: from, err := eth.txPool.GetSender(event.Tx) @@ -233,7 +237,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { case <-time.After(time.Duration(10) * time.Second): return fmt.Errorf("Time out waiting for confirmation from m2") } - subEvent.Unsubscribe() } return nil } diff --git a/eth/downloader/api.go b/eth/downloader/api.go index d496fa6a4d..581e9aed24 100644 --- a/eth/downloader/api.go +++ b/eth/downloader/api.go @@ -40,8 +40,8 @@ type PublicDownloaderAPI struct { // installSyncSubscription channel. func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAPI { api := &PublicDownloaderAPI{ - d: d, - mux: m, + d: d, + mux: m, installSyncSubscription: make(chan chan interface{}), uninstallSyncSubscription: make(chan *uninstallSyncSubscriptionRequest), } diff --git a/eth/handler_test.go b/eth/handler_test.go index e336dfa285..923df129a0 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -242,10 +242,10 @@ func testGetBlockBodies(t *testing.T, protocol int) { available []bool // Availability of explicitly requested blocks expected int // Total number of existing blocks to expect }{ - {1, nil, nil, 1}, // A single random block should be retrievable - {10, nil, nil, 10}, // Multiple random blocks should be retrievable - {limit, nil, nil, limit}, // The maximum possible blocks should be retrievable - {limit + 1, nil, nil, limit}, // No more than the possible block count should be returned + {1, nil, nil, 1}, // A single random block should be retrievable + {10, nil, nil, 10}, // Multiple random blocks should be retrievable + {limit, nil, nil, limit}, // The maximum possible blocks should be retrievable + {limit + 1, nil, nil, limit}, // No more than the possible block count should be returned {0, []common.Hash{pm.blockchain.Genesis().Hash()}, []bool{true}, 1}, // The genesis block should be retrievable {0, []common.Hash{pm.blockchain.CurrentBlock().Hash()}, []bool{true}, 1}, // The chains head block should be retrievable {0, []common.Hash{{}}, []bool{false}, 0}, // A non existent block should not be returned diff --git a/p2p/dial.go b/p2p/dial.go index 3a6cff18c1..f6ef432846 100644 --- a/p2p/dial.go +++ b/p2p/dial.go @@ -318,7 +318,7 @@ func (t *dialTask) Do(srv *Server) { } } if err == nil { - log.Trace("Dial pair connection sucess", "task", t.dest) + log.Trace("Dial pair connection success", "task", t.dest) } else { log.Trace("Dial pair connection error", "task", t.dest, "err", err) } diff --git a/swarm/api/http/error.go b/swarm/api/http/error.go index 9a65412cf9..2f77f2784a 100644 --- a/swarm/api/http/error.go +++ b/swarm/api/http/error.go @@ -71,7 +71,7 @@ func initErrHandling() { multipleChoicesPage := GetMultipleChoicesErrorPage() //map the codes to the available pages tnames := map[int]string{ - 0: genErrPage, //default + 0: genErrPage, //default http.StatusBadRequest: genErrPage, http.StatusNotFound: notFoundPage, http.StatusMultipleChoices: multipleChoicesPage,