Skip to content

Commit

Permalink
Merge pull request expanse-org#37 from dinhln89/master
Browse files Browse the repository at this point in the history
Signing transaction.
  • Loading branch information
ngtuna committed Jun 14, 2018
2 parents 4c17084 + 0411e22 commit 719db78
Show file tree
Hide file tree
Showing 6 changed files with 880 additions and 10 deletions.
1 change: 1 addition & 0 deletions common/types.go
Expand Up @@ -30,6 +30,7 @@ import (
const (
HashLength = 32
AddressLength = 20
BlockSigners = "0x0000000000000000000000000000000000000089"
)

var (
Expand Down
4 changes: 4 additions & 0 deletions consensus/clique/clique.go
Expand Up @@ -775,3 +775,7 @@ func (c *Clique) accumulateRewards(chain consensus.ChainReader, state *state.Sta

return nil
}

func (c *Clique) RecoverSigner(header *types.Header) (common.Address, error) {
return ecrecover(header, c.signatures)
}
25 changes: 15 additions & 10 deletions core/tx_pool.go
Expand Up @@ -293,11 +293,11 @@ func (pool *TxPool) loop() {

pool.mu.Unlock()
}
// Be unsubscribed due to system stopped
// Be unsubscribed due to system stopped
case <-pool.chainHeadSub.Err():
return

// Handle stats reporting ticks
// Handle stats reporting ticks
case <-report.C:
pool.mu.RLock()
pending, queued := pool.stats()
Expand All @@ -309,7 +309,7 @@ func (pool *TxPool) loop() {
prevPending, prevQueued, prevStales = pending, queued, stales
}

// Handle inactive account transaction eviction
// Handle inactive account transaction eviction
case <-evict.C:
pool.mu.Lock()
for addr := range pool.queue {
Expand All @@ -326,7 +326,7 @@ func (pool *TxPool) loop() {
}
pool.mu.Unlock()

// Handle local transaction journal rotation
// Handle local transaction journal rotation
case <-journal.C:
if pool.journal != nil {
pool.mu.Lock()
Expand Down Expand Up @@ -586,13 +586,17 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if pool.currentState.GetBalance(from).Cmp(tx.Cost()) < 0 {
return ErrInsufficientFunds
}
intrGas, err := IntrinsicGas(tx.Data(), tx.To() == nil, pool.homestead)
if err != nil {
return err
}
if tx.Gas() < intrGas {
return ErrIntrinsicGas
if tx.To().String() != common.BlockSigners {
intrGas, err := IntrinsicGas(tx.Data(), tx.To() == nil, pool.homestead)
if err != nil {
return err
}
// Exclude check smart contract sign address.
if tx.Gas() < intrGas {
return ErrIntrinsicGas
}
}

return nil
}

Expand All @@ -611,6 +615,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
log.Trace("Discarding already known transaction", "hash", hash)
return false, fmt.Errorf("known transaction: %x", hash)
}

// If the transaction fails basic validation, discard it
if err := pool.validateTx(tx, local); err != nil {
log.Trace("Discarding invalid transaction", "hash", hash, "err", err)
Expand Down

0 comments on commit 719db78

Please sign in to comment.