Skip to content

Commit

Permalink
moves check for frozen gold transfers to after check that transactor …
Browse files Browse the repository at this point in the history
…balance covers gas (#895)
  • Loading branch information
alecps authored Mar 6, 2020
1 parent 5388d64 commit dccce21
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
30 changes: 15 additions & 15 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,21 +551,6 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return ErrInvalidSender
}

// Ensure gold transfers are whitelisted if transfers are frozen.
if tx.Value().Sign() > 0 {
to := *tx.To()
if isFrozen, err := freezer.IsFrozen(params.GoldTokenRegistryId, nil, nil); err != nil {
log.Warn("Error determining if transfers are frozen, will proceed as if they are not", "err", err)
} else if isFrozen {
log.Info("Transfers are frozen")
if !transfer_whitelist.IsWhitelisted(to, from, nil, nil) {
log.Debug("Attempt to transfer between non-whitelisted addresses", "hash", tx.Hash(), "to", to, "from", from)
return ErrTransfersFrozen
}
log.Info("Transfer is whitelisted", "hash", tx.Hash(), "to", to, "from", from)
}
}

// Ensure the fee currency is native or whitelisted.
if tx.FeeCurrency() != nil && !currency.IsWhitelisted(*tx.FeeCurrency(), nil, nil) {
return ErrNonWhitelistedFeeCurrency
Expand Down Expand Up @@ -606,6 +591,21 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return ErrGasPriceDoesNotExceedMinimum
}

// Ensure gold transfers are whitelisted if transfers are frozen.
if tx.Value().Sign() > 0 {
to := *tx.To()
if isFrozen, err := freezer.IsFrozen(params.GoldTokenRegistryId, nil, nil); err != nil {
log.Warn("Error determining if transfers are frozen, will proceed as if they are not", "err", err)
} else if isFrozen {
log.Info("Transfers are frozen")
if !transfer_whitelist.IsWhitelisted(to, from, nil, nil) {
log.Debug("Attempt to transfer between non-whitelisted addresses", "hash", tx.Hash(), "to", to, "from", from)
return ErrTransfersFrozen
}
log.Info("Transfer is whitelisted", "hash", tx.Hash(), "to", to, "from", from)
}
}

return nil
}

Expand Down
30 changes: 15 additions & 15 deletions light/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,21 +367,6 @@ func (pool *TxPool) validateTx(ctx context.Context, tx *types.Transaction) error
return core.ErrNonceTooLow
}

// Ensure gold transfers are whitelisted if transfers are frozen.
if tx.Value().Sign() > 0 {
to := *tx.To()
if isFrozen, err := freezer.IsFrozen(params.GoldTokenRegistryId, nil, nil); err != nil {
log.Warn("Error determining if transfers are frozen, will proceed as if they are not", "err", err)
} else if isFrozen {
log.Info("Transfers are frozen")
if !transfer_whitelist.IsWhitelisted(to, from, nil, nil) {
log.Debug("Attempt to transfer between non-whitelisted addresses", "hash", tx.Hash(), "to", to, "from", from)
return core.ErrTransfersFrozen
}
log.Info("Transfer is whitelisted", "hash", tx.Hash(), "to", to, "from", from)
}
}

// Check the transaction doesn't exceed the current
// block limit gas.
header := pool.chain.GetHeaderByHash(pool.head)
Expand Down Expand Up @@ -411,6 +396,21 @@ func (pool *TxPool) validateTx(ctx context.Context, tx *types.Transaction) error
return core.ErrIntrinsicGas
}

// Ensure gold transfers are whitelisted if transfers are frozen.
if tx.Value().Sign() > 0 {
to := *tx.To()
if isFrozen, err := freezer.IsFrozen(params.GoldTokenRegistryId, nil, nil); err != nil {
log.Warn("Error determining if transfers are frozen, will proceed as if they are not", "err", err)
} else if isFrozen {
log.Info("Transfers are frozen")
if !transfer_whitelist.IsWhitelisted(to, from, nil, nil) {
log.Debug("Attempt to transfer between non-whitelisted addresses", "hash", tx.Hash(), "to", to, "from", from)
return core.ErrTransfersFrozen
}
log.Info("Transfer is whitelisted", "hash", tx.Hash(), "to", to, "from", from)
}
}

// Should have a peer that will accept and broadcast our transaction
if err := pool.relay.HasPeerWithEtherbase(tx.GatewayFeeRecipient()); err != nil {
return err
Expand Down

0 comments on commit dccce21

Please sign in to comment.