remove bad practice code and add tx

pull/902/head
Minh Doan 6 years ago committed by Minh Doan
parent c125e48ac5
commit a5d14e6c52
  1. 14
      core/api_backend.go
  2. 1
      core/tx_pool.go
  3. 7
      node/node.go
  4. 2
      node/rpc.go
  5. 20
      node/staking_test.go

@ -15,14 +15,15 @@ import (
// HmyAPIBackend ...
type HmyAPIBackend struct {
blockchain *BlockChain
txPool *TxPool
accountManager *accounts.Manager
blockchain *BlockChain
txPool *TxPool
accountManager *accounts.Manager
addPendingTransaction func(newTx *types.Transaction)
}
// NewBackend ...
func NewBackend(blockchain *BlockChain, txPool *TxPool, accountManager *accounts.Manager) *HmyAPIBackend {
return &HmyAPIBackend{blockchain, txPool, accountManager}
func NewBackend(blockchain *BlockChain, txPool *TxPool, accountManager *accounts.Manager, addPendingTransaction func(newTx *types.Transaction)) *HmyAPIBackend {
return &HmyAPIBackend{blockchain, txPool, accountManager, addPendingTransaction}
}
// ChainDb ...
@ -88,7 +89,8 @@ func (b *HmyAPIBackend) GetPoolNonce(ctx context.Context, addr common.Address) (
// SendTx ...
func (b *HmyAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error {
return b.txPool.Add(ctx, signedTx)
b.addPendingTransaction(signedTx)
return nil
}
// ChainConfig ...

@ -695,6 +695,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) {
// backend
func (pool *TxPool) Add(ctx context.Context, tx *types.Transaction) error {
// TODO(ricl): placeholder
// TODO(minhdoan): follow with richard why we need this. As of now TxPool is not used now.
return nil
}

@ -229,6 +229,13 @@ func (node *Node) addPendingTransactions(newTxs types.Transactions) {
utils.GetLogInstance().Debug("Got more transactions", "num", len(newTxs), "totalPending", len(node.pendingTransactions))
}
func (node *Node) addPendingTransaction(newTx *types.Transaction) {
node.pendingTxMutex.Lock()
node.pendingTransactions = append(node.pendingTransactions, newTx)
node.pendingTxMutex.Unlock()
utils.GetLogInstance().Debug("Got ONE more transaction", "totalPending", len(node.pendingTransactions))
}
// Take out a subset of valid transactions from the pending transaction list
// Note the pending transaction list will then contain the rest of the txs
func (node *Node) getTransactionsForNewBlock(maxNumTxs int) types.Transactions {

@ -42,7 +42,7 @@ var (
// StartRPC start RPC service
func (node *Node) StartRPC(nodePort string) error {
// Gather all the possible APIs to surface
apiBackend = core.NewBackend(node.Blockchain(), node.TxPool, node.accountManager)
apiBackend = core.NewBackend(node.Blockchain(), node.TxPool, node.accountManager, node.addPendingTransaction)
apis := hmyapi.GetAPIs(apiBackend)
for _, service := range node.serviceManager.GetServices() {

@ -4,12 +4,10 @@ import (
"math/big"
"testing"
"github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/contracts/structs"
"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/contracts/structs"
"github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/p2pimpl"
@ -48,13 +46,13 @@ func TestUpdateStakingList(t *testing.T) {
}
stakeInfo := &structs.StakeInfoReturnValue{
[]common.Address{testAddress},
[][32]byte{testBlsPubKey1},
[][32]byte{testBlsPubKey2},
[][32]byte{testBlsPubKey3},
[]*big.Int{blockNum},
[]*big.Int{lockPeriodCount},
[]*big.Int{amount},
LockedAddresses: []common.Address{testAddress},
BlsPubicKeys1: [][32]byte{testBlsPubKey1},
BlsPubicKeys2: [][32]byte{testBlsPubKey2},
BlsPubicKeys3: [][32]byte{testBlsPubKey3},
BlockNums: []*big.Int{blockNum},
LockPeriodCounts: []*big.Int{lockPeriodCount},
Amounts: []*big.Int{amount},
}
node.UpdateStakingList(stakeInfo)

Loading…
Cancel
Save