Skip to content

Commit

Permalink
Merge pull request ethereum#231 from nguyenbatam/move_subscribeTx_sub…
Browse files Browse the repository at this point in the history
…scribeSpecialTx

move from Subscribe Tx to Subscribe Special Tx in Double Validate
  • Loading branch information
ngtuna authored Oct 23, 2018
2 parents 3b4106f + 1afaa5f commit 996f858
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))},
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
9 changes: 6 additions & 3 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions eth/downloader/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
8 changes: 4 additions & 4 deletions eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion p2p/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion swarm/api/http/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 996f858

Please sign in to comment.