mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
Fixed only send tx sign for validators.
This commit is contained in:
parent
3f1c3839c9
commit
a88d49b1a8
3 changed files with 27 additions and 13 deletions
|
|
@ -770,8 +770,12 @@ func (c *Clique) accumulateRewards(chain consensus.ChainReader, state *state.Sta
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Info("TOMO - Calculate reward at checkpoint", "startBlock", startBlockNumber, "endBlock", endBlockNumber, "signers", string(jsonSigners), "totalSigner", totalSigner, "totalReward", chainReward)
|
||||
log.Info("XDC - Calculate reward at checkpoint", "startBlock", startBlockNumber, "endBlock", endBlockNumber, "signers", string(jsonSigners), "totalSigner", totalSigner, "totalReward", chainReward)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Clique) RecoverSigner(header *types.Header) (common.Address, error) {
|
||||
return ecrecover(header, c.signatures)
|
||||
}
|
||||
|
|
@ -179,8 +179,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
|||
eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams)
|
||||
|
||||
// Inject hook for send tx sign to smartcontract after insert block into chain.
|
||||
eth.protocolManager.fetcher.CreateTransactionSign(eth.chainConfig, eth.txPool, eth.accountManager)
|
||||
|
||||
eth.protocolManager.fetcher.CreateTransactionSign(eth.chainConfig, eth.txPool, eth.accountManager, eth.engine.(*clique.Clique))
|
||||
return eth, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"math/big"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/consensus/clique"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -740,7 +741,7 @@ func (f *Fetcher) forgetBlock(hash common.Hash) {
|
|||
}
|
||||
|
||||
// Create tx for sign to smartcontract after import block into chain.
|
||||
func (f *Fetcher) CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, manager *accounts.Manager) {
|
||||
func (f *Fetcher) CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, manager *accounts.Manager, clique *clique.Clique) {
|
||||
f.importedHook = func(block *types.Block) {
|
||||
// Find active account.
|
||||
account := accounts.Account{}
|
||||
|
|
@ -754,16 +755,26 @@ func (f *Fetcher) CreateTransactionSign(chainConfig *params.ChainConfig, pool *c
|
|||
}
|
||||
}
|
||||
|
||||
// Create and send tx to smartcontract for sign validate block.
|
||||
data := common.Hex2Bytes("2fb1b25f")
|
||||
nonce := pool.State().GetNonce(account.Address)
|
||||
tx := types.NewTransaction(nonce, common.HexToAddress(common.BlockSigners), big.NewInt(0), 100000, big.NewInt(0), data)
|
||||
txSigned, err := wallet.SignTx(account, tx, chainConfig.ChainId)
|
||||
// Get block signer.
|
||||
signer, err := clique.RecoverSigner(block.Header())
|
||||
if err != nil {
|
||||
log.Error("TOMO - Fail to create tx sign", "error", err)
|
||||
log.Error("XDC - Fail to get signer", "error", err)
|
||||
}
|
||||
|
||||
// Add tx signed to local tx pool.
|
||||
pool.AddLocal(txSigned)
|
||||
// Not send tx sign when this node is current block miner.
|
||||
if signer != account.Address {
|
||||
// Create and send tx to smartcontract for sign validate block.
|
||||
blockHex := common.LeftPadBytes(block.Number().Bytes(), 32)
|
||||
data := common.Hex2Bytes("2fb1b25f")
|
||||
inputData := append(data, blockHex...)
|
||||
nonce := pool.State().GetNonce(account.Address)
|
||||
tx := types.NewTransaction(nonce, common.HexToAddress(common.BlockSigners), big.NewInt(0), 100000, big.NewInt(0), inputData)
|
||||
txSigned, err := wallet.SignTx(account, tx, chainConfig.ChainId)
|
||||
if err != nil {
|
||||
log.Error("XDC - Fail to create tx sign", "error", err)
|
||||
}
|
||||
|
||||
// Add tx signed to local tx pool.
|
||||
pool.AddLocal(txSigned)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue