Fix getFreeToken blocking issue

pull/754/head
Rongjian Lan 6 years ago
parent def32c9bee
commit a56150a8a2
  1. 5
      node/contract.go
  2. 1
      node/node.go
  3. 7
      node/node_handler.go

@ -4,6 +4,7 @@ import (
"crypto/ecdsa" "crypto/ecdsa"
"math/big" "math/big"
"strings" "strings"
"sync/atomic"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -170,8 +171,8 @@ func (node *Node) CallFaucetContract(address common.Address) common.Hash {
} }
func (node *Node) callGetFreeToken(address common.Address) common.Hash { func (node *Node) callGetFreeToken(address common.Address) common.Hash {
nonce := node.GetNonceOfAddress(crypto.PubkeyToAddress(node.ContractDeployerKey.PublicKey)) nonce := atomic.AddUint64(&node.ContractDeployerCurrentNonce, 1)
return node.callGetFreeTokenWithNonce(address, nonce) return node.callGetFreeTokenWithNonce(address, nonce-1)
} }
func (node *Node) callGetFreeTokenWithNonce(address common.Address, nonce uint64) common.Hash { func (node *Node) callGetFreeTokenWithNonce(address common.Address, nonce uint64) common.Hash {

@ -146,6 +146,7 @@ type Node struct {
// For test only // For test only
TestBankKeys []*ecdsa.PrivateKey TestBankKeys []*ecdsa.PrivateKey
ContractDeployerKey *ecdsa.PrivateKey ContractDeployerKey *ecdsa.PrivateKey
ContractDeployerCurrentNonce uint64 // The nonce of the deployer contract at current block
ContractAddresses []common.Address ContractAddresses []common.Address
// Shard group Message Receiver // Shard group Message Receiver

@ -11,9 +11,12 @@ import (
"os" "os"
"os/exec" "os/exec"
"strconv" "strconv"
"sync/atomic"
"syscall" "syscall"
"time" "time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -315,6 +318,10 @@ func (node *Node) PostConsensusProcessing(newBlock *types.Block) {
node.AddNewBlock(newBlock) node.AddNewBlock(newBlock)
// Update contract deployer's nonce so default contract like faucet can issue transaction with current nonce
nonce := node.GetNonceOfAddress(crypto.PubkeyToAddress(node.ContractDeployerKey.PublicKey))
atomic.StoreUint64(&node.ContractDeployerCurrentNonce, nonce)
if node.Consensus.ShardID == 0 { if node.Consensus.ShardID == 0 {
// ConfirmedBlockChannel which is listened by drand leader who will initiate DRG if its a epoch block (first block of a epoch) // ConfirmedBlockChannel which is listened by drand leader who will initiate DRG if its a epoch block (first block of a epoch)

Loading…
Cancel
Save