update block signer with epochNumber

This commit is contained in:
Nguyen Sy Thanh Son 2018-07-27 08:55:38 +00:00
parent 2cfae3e48a
commit 908385b31d
4 changed files with 8 additions and 7 deletions

View file

@ -170,7 +170,8 @@ func (w *wizard) makeGenesis() {
fmt.Println()
fmt.Println("How many blocks per checkpoint? (default = 990)")
genesis.Config.Clique.RewardCheckpoint = uint64(w.readDefaultInt(990))
epochNumber := w.readDefaultInt(990)
genesis.Config.Clique.RewardCheckpoint = uint64(epochNumber)
// Validator Smart Contract Code
pKey, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
@ -201,7 +202,7 @@ func (w *wizard) makeGenesis() {
}
// Block Signers Smart Contract
blockSignerAddress, _, err := blockSignerContract.DeployBlockSigner(transactOpts, contractBackend)
blockSignerAddress, _, err := blockSignerContract.DeployBlockSigner(transactOpts, contractBackend, big.NewInt(int64(epochNumber)))
if err != nil {
fmt.Println("Can't deploy root registry")
}

View file

@ -42,8 +42,8 @@ func NewBlockSigner(transactOpts *bind.TransactOpts, contractAddr common.Address
}, nil
}
func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend) (common.Address, *BlockSigner, error) {
blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, big.NewInt(99))
func DeployBlockSigner(transactOpts *bind.TransactOpts, contractBackend bind.ContractBackend, epochNumber *big.Int) (common.Address, *BlockSigner, error) {
blockSignerAddr, _, _, err := contract.DeployBlockSigner(transactOpts, contractBackend, epochNumber)
if err != nil {
return blockSignerAddr, nil, err
}

View file

@ -38,7 +38,7 @@ func TestBlockSigner(t *testing.T) {
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
transactOpts := bind.NewKeyedTransactor(key)
blockSignerAddress, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend)
blockSignerAddress, blockSigner, err := DeployBlockSigner(transactOpts, contractBackend, big.NewInt(99))
if err != nil {
t.Fatalf("can't deploy root registry: %v", err)
}

View file

@ -17,8 +17,8 @@ contract BlockSigner {
function sign(uint256 _blockNumber, bytes32 _blockHash) external {
// consensus should validate all senders are validators, gas = 0
//require(block.number >= _blockNumber);
//require(block.number <= _blockNumber.add(epochNumber * 2));
require(block.number >= _blockNumber);
require(block.number <= _blockNumber.add(epochNumber * 2));
blocks[_blockNumber].push(_blockHash);
blockSigners[_blockHash].push(msg.sender);