move from SubscribeTx to Subscribe Special Tx in Double Validate

This commit is contained in:
Nguyen Ba Tam 2018-10-23 17:33:40 +07:00
parent 3b4106fc12
commit 1afaa5f89e
7 changed files with 16 additions and 13 deletions

View file

@ -366,7 +366,7 @@ func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis {
common.BytesToAddress([]byte{6}): {Balance: big.NewInt(1)}, // ECAdd common.BytesToAddress([]byte{6}): {Balance: big.NewInt(1)}, // ECAdd
common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul
common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing 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))},
}, },
} }
} }

View file

@ -81,7 +81,7 @@ var (
ErrZeroGasPrice = errors.New("zero gas price") ErrZeroGasPrice = errors.New("zero gas price")
ErrDuplicateSpecialTransaction = errors.New("duplicate a specail transaction") ErrDuplicateSpecialTransaction = errors.New("duplicate a special transaction")
) )
var ( var (

View file

@ -192,6 +192,9 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
// Hook double validation // Hook double validation
doubleValidateHook := func(block *types.Block) error { doubleValidateHook := func(block *types.Block) error {
parentBlk := eth.blockchain.GetBlockByHash(block.ParentHash()) 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()) snap, err := c.GetSnapshot(eth.blockchain, parentBlk.Header())
if err != nil { if err != nil {
if err == consensus.ErrUnknownAncestor { 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) return fmt.Errorf("Fail to validate M2 condition for importing block: %v", err)
} }
if eth.etherbase != m2 { if eth.etherbase != m2 {
txCh := make(chan core.TxPreEvent, txChanSize)
subEvent := eth.txPool.SubscribeSpecialTxPreEvent(txCh)
defer subEvent.Unsubscribe()
// firstly, look into pending txPool // firstly, look into pending txPool
pendingMap, err := eth.txPool.Pending() pendingMap, err := eth.txPool.Pending()
if err != nil { 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 //then wait until signTx from m2 comes into txPool
txCh := make(chan core.TxPreEvent, txChanSize)
subEvent := eth.txPool.SubscribeTxPreEvent(txCh)
select { select {
case event := <-txCh: case event := <-txCh:
from, err := eth.txPool.GetSender(event.Tx) 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): case <-time.After(time.Duration(10) * time.Second):
return fmt.Errorf("Time out waiting for confirmation from m2") return fmt.Errorf("Time out waiting for confirmation from m2")
} }
subEvent.Unsubscribe()
} }
return nil return nil
} }

View file

@ -40,8 +40,8 @@ type PublicDownloaderAPI struct {
// installSyncSubscription channel. // installSyncSubscription channel.
func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAPI { func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAPI {
api := &PublicDownloaderAPI{ api := &PublicDownloaderAPI{
d: d, d: d,
mux: m, mux: m,
installSyncSubscription: make(chan chan interface{}), installSyncSubscription: make(chan chan interface{}),
uninstallSyncSubscription: make(chan *uninstallSyncSubscriptionRequest), uninstallSyncSubscription: make(chan *uninstallSyncSubscriptionRequest),
} }

View file

@ -242,10 +242,10 @@ func testGetBlockBodies(t *testing.T, protocol int) {
available []bool // Availability of explicitly requested blocks available []bool // Availability of explicitly requested blocks
expected int // Total number of existing blocks to expect expected int // Total number of existing blocks to expect
}{ }{
{1, nil, nil, 1}, // A single random block should be retrievable {1, nil, nil, 1}, // A single random block should be retrievable
{10, nil, nil, 10}, // Multiple random blocks 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, 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 {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.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{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 {0, []common.Hash{{}}, []bool{false}, 0}, // A non existent block should not be returned

View file

@ -318,7 +318,7 @@ func (t *dialTask) Do(srv *Server) {
} }
} }
if err == nil { if err == nil {
log.Trace("Dial pair connection sucess", "task", t.dest) log.Trace("Dial pair connection success", "task", t.dest)
} else { } else {
log.Trace("Dial pair connection error", "task", t.dest, "err", err) log.Trace("Dial pair connection error", "task", t.dest, "err", err)
} }

View file

@ -71,7 +71,7 @@ func initErrHandling() {
multipleChoicesPage := GetMultipleChoicesErrorPage() multipleChoicesPage := GetMultipleChoicesErrorPage()
//map the codes to the available pages //map the codes to the available pages
tnames := map[int]string{ tnames := map[int]string{
0: genErrPage, //default 0: genErrPage, //default
http.StatusBadRequest: genErrPage, http.StatusBadRequest: genErrPage,
http.StatusNotFound: notFoundPage, http.StatusNotFound: notFoundPage,
http.StatusMultipleChoices: multipleChoicesPage, http.StatusMultipleChoices: multipleChoicesPage,