mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
Revert Randomization implementation
This commit is contained in:
parent
c9ad5cedb2
commit
944494f6e4
22 changed files with 56 additions and 607 deletions
|
|
@ -77,7 +77,7 @@ var daoProForkGenesis = `{
|
|||
}
|
||||
}`
|
||||
|
||||
var daoGenesisHash = common.HexToHash("f2ea0466bf5a07cb7407474d9fbaae6e275127f038ca57a673b833234204f4fd")
|
||||
var daoGenesisHash = common.HexToHash("5e1fc79cb4ffa4739177b5408045cd5d51c6cf766133f23f7cd72ee1f8d790e0")
|
||||
var daoGenesisForkBlock = big.NewInt(314)
|
||||
|
||||
// TestDAOForkBlockNewChain tests that the DAO hard-fork number and the nodes support/opposition is correctly
|
||||
|
|
@ -127,11 +127,10 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc
|
|||
}
|
||||
defer db.Close()
|
||||
|
||||
genesisHash := common.HexToHash("2efa267fef46877ac2659209e2299f97b0afc2a797ee8672db21920a5151e0aa")
|
||||
genesisHash := common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
|
||||
if genesis != "" {
|
||||
genesisHash = daoGenesisHash
|
||||
}
|
||||
t.Log("genesisHash", genesisHash.String())
|
||||
config, err := core.GetChainConfig(db, genesisHash)
|
||||
if err != nil {
|
||||
t.Errorf("test %d: failed to retrieve chain config: %v", test, err)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import (
|
|||
const SafeMathABI = "[]"
|
||||
|
||||
// SafeMathBin is the compiled bytecode used for deploying new contracts.
|
||||
const SafeMathBin = `0x604c602c600b82828239805160001a60731460008114601c57601e565bfe5b5030600052607381538281f30073000000000000000000000000000000000000000030146080604052600080fd00a165627a7a72305820a3f63b465e1cf25f306b1eb1efefc8dac3c38993a7340f69d8b470c3bf599ff30029`
|
||||
const SafeMathBin = `0x604c602c600b82828239805160001a60731460008114601c57601e565bfe5b5030600052607381538281f30073000000000000000000000000000000000000000030146060604052600080fd00a165627a7a72305820b9407d48ebc7efee5c9f08b3b3a957df2939281f5913225e8c1291f069b900490029`
|
||||
|
||||
// DeploySafeMath deploys a new Ethereum contract, binding an instance of SafeMath to it.
|
||||
func DeploySafeMath(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *SafeMath, error) {
|
||||
|
|
@ -178,7 +178,7 @@ func (_SafeMath *SafeMathTransactorRaw) Transact(opts *bind.TransactOpts, method
|
|||
const XDCRandomizeABI = "[{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getSecret\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_secret\",\"type\":\"bytes32[]\"}],\"name\":\"setSecret\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"randomNumber\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\"}],\"name\":\"getOpening\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_opening\",\"type\":\"bytes32\"}],\"name\":\"setOpening\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"_randomNumber\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]"
|
||||
|
||||
// XDCRandomizeBin is the compiled bytecode used for deploying new contracts.
|
||||
const XDCRandomizeBin = `0x608060405234801561001057600080fd5b5060405160208061035b8339810160405251600055610327806100346000396000f30060806040526004361061006c5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663284180fc811461007157806334d38600146100ef578063ccbac9f514610146578063d442d6cc1461016d578063e11f5ba21461019b575b600080fd5b34801561007d57600080fd5b5061009f73ffffffffffffffffffffffffffffffffffffffff600435166101b3565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156100db5781810151838201526020016100c3565b505050509050019250505060405180910390f35b3480156100fb57600080fd5b50604080516020600480358082013583810280860185019096528085526101449536959394602494938501929182918501908490808284375094975061022d9650505050505050565b005b34801561015257600080fd5b5061015b610251565b60408051918252519081900360200190f35b34801561017957600080fd5b5061015b73ffffffffffffffffffffffffffffffffffffffff60043516610257565b3480156101a757600080fd5b5061014460043561027f565b73ffffffffffffffffffffffffffffffffffffffff811660009081526001602090815260409182902080548351818402810184019094528084526060939283018282801561022157602002820191906000526020600020905b8154815260019091019060200180831161020c575b50505050509050919050565b336000908152600160209081526040909120825161024d92840190610291565b5050565b60005481565b73ffffffffffffffffffffffffffffffffffffffff1660009081526002602052604090205490565b33600090815260026020526040902055565b8280548282559060005260206000209081019282156102ce579160200282015b828111156102ce57825182556020909201916001909101906102b1565b506102da9291506102de565b5090565b6102f891905b808211156102da57600081556001016102e4565b905600a165627a7a7230582027c1c755e5d546967a2057a4338eb36cf7ec5972758d7f7a8427abdfc890bd590029`
|
||||
const XDCRandomizeBin = `0x6060604052341561000f57600080fd5b604051602080610359833981016040528080516000555050610323806100366000396000f30060606040526004361061006c5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663284180fc811461007157806334d38600146100e3578063ccbac9f514610134578063d442d6cc14610159578063e11f5ba214610178575b600080fd5b341561007c57600080fd5b610090600160a060020a036004351661018e565b60405160208082528190810183818151815260200191508051906020019060200280838360005b838110156100cf5780820151838201526020016100b7565b505050509050019250505060405180910390f35b34156100ee57600080fd5b610132600460248135818101908301358060208181020160405190810160405280939291908181526020018383602002808284375094965061021295505050505050565b005b341561013f57600080fd5b61014761023f565b60405190815260200160405180910390f35b341561016457600080fd5b610147600160a060020a0360043516610245565b341561018357600080fd5b610132600435610260565b61019661027b565b6001600083600160a060020a0316600160a060020a0316815260200190815260200160002080548060200260200160405190810160405280929190818152602001828054801561020657602002820191906000526020600020905b815481526001909101906020018083116101f1575b50505050509050919050565b600160a060020a033316600090815260016020526040902081805161023b92916020019061028d565b5050565b60005481565b600160a060020a031660009081526002602052604090205490565b600160a060020a033316600090815260026020526040902055565b60206040519081016040526000815290565b8280548282559060005260206000209081019282156102ca579160200282015b828111156102ca57825182556020909201916001909101906102ad565b506102d69291506102da565b5090565b6102f491905b808211156102d657600081556001016102e0565b905600a165627a7a7230582043a345787b9942e3361515ce1a0a4dbaab0ed6ce42c6ca0344119134351d9ffe0029`
|
||||
|
||||
// DeployXDCRandomize deploys a new Ethereum contract, binding an instance of XDCRandomize to it.
|
||||
func DeployXDCRandomize(auth *bind.TransactOpts, backend bind.ContractBackend, _randomNumber *big.Int) (common.Address, *types.Transaction, *XDCRandomize, error) {
|
||||
|
|
|
|||
|
|
@ -9,25 +9,19 @@ import (
|
|||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/contracts"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
)
|
||||
|
||||
var (
|
||||
epocNumber = int64(12)
|
||||
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||
addr = crypto.PubkeyToAddress(key.PublicKey)
|
||||
byte0 = make([][32]byte, epocNumber)
|
||||
acc1Key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
|
||||
acc1Addr = crypto.PubkeyToAddress(acc1Key.PublicKey)
|
||||
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||
addr = crypto.PubkeyToAddress(key.PublicKey)
|
||||
byte0 = make([][32]byte, 2)
|
||||
)
|
||||
|
||||
func TestRandomize(t *testing.T) {
|
||||
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(100000000000000)}})
|
||||
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}})
|
||||
transactOpts := bind.NewKeyedTransactor(key)
|
||||
transactOpts.GasLimit = 1000000
|
||||
|
||||
randomizeAddress, randomize, err := DeployRandomize(transactOpts, contractBackend, big.NewInt(2))
|
||||
t.Log("contract address", randomizeAddress.String())
|
||||
|
|
@ -46,80 +40,11 @@ func TestRandomize(t *testing.T) {
|
|||
return true
|
||||
}
|
||||
contractBackend.ForEachStorageAt(ctx, randomizeAddress, nil, f)
|
||||
|
||||
s, err := randomize.SetSecret(byte0)
|
||||
if err != nil {
|
||||
t.Fatalf("can't set secret: %v", err)
|
||||
t.Fatalf("can't get secret: %v", err)
|
||||
}
|
||||
t.Log("tx data", s)
|
||||
contractBackend.Commit()
|
||||
}
|
||||
|
||||
func TestSendTxRandomizeSecretAndOpening(t *testing.T) {
|
||||
genesis := core.GenesisAlloc{acc1Addr: {Balance: big.NewInt(1000000000000)}}
|
||||
backend := backends.NewSimulatedBackend(genesis)
|
||||
backend.Commit()
|
||||
signer := types.HomesteadSigner{}
|
||||
ctx := context.Background()
|
||||
|
||||
transactOpts := bind.NewKeyedTransactor(acc1Key)
|
||||
transactOpts.GasLimit = 4200000
|
||||
epocNumber := uint64(900)
|
||||
randomizeAddr, randomizeContract, err := DeployRandomize(transactOpts, backend, new(big.Int).SetInt64(0))
|
||||
if err != nil {
|
||||
t.Fatalf("Can't deploy randomize SC: %v", err)
|
||||
}
|
||||
backend.Commit()
|
||||
|
||||
nonce := uint64(1)
|
||||
randomizeKeyValue := contracts.RandStringByte(32)
|
||||
tx, err := contracts.BuildTxSecretRandomize(nonce, randomizeAddr, epocNumber, randomizeKeyValue)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't create tx randomize secret: %v", err)
|
||||
}
|
||||
tx, err = types.SignTx(tx, signer, acc1Key)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't sign tx randomize secret: %v", err)
|
||||
}
|
||||
|
||||
err = backend.SendTransaction(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't send tx for create randomize secret: %v", err)
|
||||
}
|
||||
backend.Commit()
|
||||
// Increment nonce.
|
||||
nonce++
|
||||
// Set opening.
|
||||
tx, err = contracts.BuildTxOpeningRandomize(nonce, randomizeAddr, randomizeKeyValue)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't create tx randomize opening: %v", err)
|
||||
}
|
||||
tx, err = types.SignTx(tx, signer, acc1Key)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't sign tx randomize opening: %v", err)
|
||||
}
|
||||
|
||||
err = backend.SendTransaction(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't send tx for create randomize opening: %v", err)
|
||||
}
|
||||
backend.Commit()
|
||||
|
||||
// Get randomize secret from SC.
|
||||
secrets, err := randomizeContract.GetSecret(acc1Addr)
|
||||
if err != nil {
|
||||
t.Error("Fail get secrets from randomize", err)
|
||||
}
|
||||
if len(secrets) <= 0 {
|
||||
t.Error("Empty get secrets from SC", err)
|
||||
}
|
||||
// Decrypt randomize from SC.
|
||||
opening, err := randomizeContract.GetOpening(acc1Addr)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't get secret from SC: %v", err)
|
||||
}
|
||||
randomize, err := contracts.DecryptRandomizeFromSecretsAndOpening(secrets, opening)
|
||||
t.Log("randomize", randomize)
|
||||
if err != nil {
|
||||
t.Error("Can't decrypt secret and opening", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,33 +1,19 @@
|
|||
package contracts
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
cryptoRand "crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/consensus"
|
||||
"github.com/ethereum/go-ethereum/contracts/blocksigner/contract"
|
||||
randomizeContract "github.com/ethereum/go-ethereum/contracts/randomize/contract"
|
||||
contractValidator "github.com/ethereum/go-ethereum/contracts/validator/contract"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/pkg/errors"
|
||||
"io"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -35,15 +21,6 @@ const (
|
|||
RewardMasterPercent = 40
|
||||
RewardVoterPercent = 50
|
||||
RewardFoundationPercent = 10
|
||||
HexSetSecret = "34d38600"
|
||||
HexSetOpening = "e11f5ba2"
|
||||
EpocBlockSecret = 800
|
||||
EpocBlockOpening = 850
|
||||
EpocBlockRandomize = 900
|
||||
MaxMasternodes = 150
|
||||
M2ByteLength = 4
|
||||
extraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
|
||||
extraSeal = 65 // Fixed number of extra-data suffix bytes reserved for signer seal
|
||||
)
|
||||
|
||||
type rewardLog struct {
|
||||
|
|
@ -52,7 +29,7 @@ type rewardLog struct {
|
|||
}
|
||||
|
||||
// Send tx sign for block number to smart contract blockSigner.
|
||||
func CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, manager *accounts.Manager, block *types.Block, chainDb ethdb.Database) error {
|
||||
func CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, manager *accounts.Manager, block *types.Block) error {
|
||||
if chainConfig.XDPoS != nil {
|
||||
// Find active account.
|
||||
account := accounts.Account{}
|
||||
|
|
@ -72,69 +49,9 @@ func CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, m
|
|||
log.Error("Fail to create tx sign", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Add tx signed to local tx pool.
|
||||
err = pool.AddLocal(txSigned)
|
||||
if err != nil {
|
||||
log.Error("Fail to add tx sign to local pool.", "error", err)
|
||||
}
|
||||
|
||||
// Create secret tx.
|
||||
blockNumber := block.Number().Uint64()
|
||||
checkNumber := blockNumber % chainConfig.XDPoS.Epoch
|
||||
// Generate random private key and save into chaindb.
|
||||
randomizeKeyName := []byte("randomizeKey")
|
||||
exist, _ := chainDb.Has(randomizeKeyName)
|
||||
|
||||
// Set secret for randomize.
|
||||
if !exist && checkNumber > 0 && EpocBlockSecret <= checkNumber && EpocBlockOpening > checkNumber {
|
||||
// Only process when private key empty in state db.
|
||||
// Save randomize key into state db.
|
||||
randomizeKeyValue := RandStringByte(32)
|
||||
chainDb.Put(randomizeKeyName, randomizeKeyValue)
|
||||
|
||||
tx, err := BuildTxSecretRandomize(nonce, common.HexToAddress(common.RandomizeSMC), chainConfig.XDPoS.Epoch, randomizeKeyValue)
|
||||
if err != nil {
|
||||
log.Error("Fail to get tx opening for randomize", "error", err)
|
||||
return err
|
||||
}
|
||||
txSigned, err := wallet.SignTx(account, tx, chainConfig.ChainId)
|
||||
if err != nil {
|
||||
log.Error("Fail to create tx secret", "error", err)
|
||||
return err
|
||||
}
|
||||
// Add tx signed to local tx pool.
|
||||
err = pool.AddLocal(txSigned)
|
||||
if err != nil {
|
||||
log.Error("Fail to add tx secret to local pool.", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Set opening for randomize.
|
||||
if exist && checkNumber > 0 && EpocBlockOpening <= checkNumber && EpocBlockRandomize >= checkNumber {
|
||||
randomizeKeyValue, err := chainDb.Get(randomizeKeyName)
|
||||
if err != nil {
|
||||
log.Error("Fail to get randomize key from state db.", "error", err)
|
||||
}
|
||||
|
||||
tx, err := BuildTxOpeningRandomize(nonce, common.HexToAddress(common.RandomizeSMC), randomizeKeyValue)
|
||||
if err != nil {
|
||||
log.Error("Fail to get tx opening for randomize", "error", err)
|
||||
return err
|
||||
}
|
||||
txSigned, err := wallet.SignTx(account, tx, chainConfig.ChainId)
|
||||
if err != nil {
|
||||
log.Error("Fail to create tx opening", "error", err)
|
||||
return err
|
||||
}
|
||||
// Add tx to pool.
|
||||
err = pool.AddLocal(txSigned)
|
||||
if err != nil {
|
||||
log.Error("Fail to add tx opening to local pool.", "error", err)
|
||||
}
|
||||
|
||||
// Clear randomize key in state db.
|
||||
chainDb.Delete(randomizeKeyName)
|
||||
}
|
||||
pool.AddLocal(txSigned)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -150,39 +67,6 @@ func CreateTxSign(blockNumber *big.Int, blockHash common.Hash, nonce uint64, blo
|
|||
return tx
|
||||
}
|
||||
|
||||
// Send secret key into randomize smartcontract.
|
||||
func BuildTxSecretRandomize(nonce uint64, randomizeAddr common.Address, epocNumber uint64, randomizeKey []byte) (*types.Transaction, error) {
|
||||
data := common.Hex2Bytes(HexSetSecret)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
secretNumb := rand.Intn(int(epocNumber))
|
||||
|
||||
// Append randomize suffix in -1, 0, 1.
|
||||
secrets := []int64{int64(secretNumb)}
|
||||
sizeOfArray := int64(32)
|
||||
|
||||
// Build extra data for tx with first position is size of array byte and second position are length of array byte.
|
||||
arrSizeOfSecrets := common.LeftPadBytes(new(big.Int).SetInt64(sizeOfArray).Bytes(), 32)
|
||||
arrLengthOfSecrets := common.LeftPadBytes(new(big.Int).SetInt64(int64(len(secrets))).Bytes(), 32)
|
||||
inputData := append(data, arrSizeOfSecrets...)
|
||||
inputData = append(inputData, arrLengthOfSecrets...)
|
||||
for _, secret := range secrets {
|
||||
encryptSecret := Encrypt(randomizeKey, new(big.Int).SetInt64(secret).String())
|
||||
inputData = append(inputData, common.LeftPadBytes([]byte(encryptSecret), int(sizeOfArray))...)
|
||||
}
|
||||
tx := types.NewTransaction(nonce, randomizeAddr, big.NewInt(0), 4200000, big.NewInt(0), inputData)
|
||||
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// Send opening to randomize SMC.
|
||||
func BuildTxOpeningRandomize(nonce uint64, randomizeAddr common.Address, randomizeKey []byte) (*types.Transaction, error) {
|
||||
data := common.Hex2Bytes(HexSetOpening)
|
||||
inputData := append(data, randomizeKey...)
|
||||
tx := types.NewTransaction(nonce, randomizeAddr, big.NewInt(0), 4200000, big.NewInt(0), inputData)
|
||||
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// Get signers signed for blockNumber from blockSigner contract.
|
||||
func GetSignersFromContract(addrBlockSigner common.Address, client bind.ContractBackend, blockHash common.Hash) ([]common.Address, error) {
|
||||
blockSigner, err := contract.NewBlockSigner(addrBlockSigner, client)
|
||||
|
|
@ -200,109 +84,6 @@ func GetSignersFromContract(addrBlockSigner common.Address, client bind.Contract
|
|||
return addrs, nil
|
||||
}
|
||||
|
||||
// Get random from randomize contract.
|
||||
func GetRandomizeFromContract(client bind.ContractBackend, addrMasternode common.Address) (int64, error) {
|
||||
randomize, err := randomizeContract.NewXDCRandomize(common.HexToAddress(common.RandomizeSMC), client)
|
||||
if err != nil {
|
||||
log.Error("Fail to get instance of randomize", "error", err)
|
||||
}
|
||||
opts := new(bind.CallOpts)
|
||||
secrets, err := randomize.GetSecret(opts, addrMasternode)
|
||||
if err != nil {
|
||||
log.Error("Fail get secrets from randomize", "error", err)
|
||||
}
|
||||
opening, err := randomize.GetOpening(opts, addrMasternode)
|
||||
if err != nil {
|
||||
log.Error("Fail get opening from randomize", "error", err)
|
||||
}
|
||||
|
||||
return DecryptRandomizeFromSecretsAndOpening(secrets, opening)
|
||||
}
|
||||
|
||||
// Generate m2 listing from randomize array.
|
||||
func GenM2FromRandomize(randomizes []int64) ([]int64, error) {
|
||||
blockValidator := NewSlice(int64(0), MaxMasternodes, 1)
|
||||
randIndexs := make([]int64, MaxMasternodes)
|
||||
total := int64(0)
|
||||
var temp int64 = 0
|
||||
for _, j := range randomizes {
|
||||
total += j
|
||||
}
|
||||
rand.Seed(total)
|
||||
for i := len(blockValidator) - 1; i >= 0; i-- {
|
||||
blockLength := len(blockValidator) - 1
|
||||
if blockLength <= 1 {
|
||||
blockLength = 1
|
||||
}
|
||||
randomIndex := int64(rand.Intn(blockLength))
|
||||
temp = blockValidator[randomIndex]
|
||||
blockValidator[randomIndex] = blockValidator[i]
|
||||
blockValidator[i] = temp
|
||||
blockValidator = append(blockValidator[:i], blockValidator[i+1:]...)
|
||||
randIndexs[i] = temp
|
||||
}
|
||||
|
||||
return randIndexs, nil
|
||||
}
|
||||
|
||||
// Get validators from m2 array integer.
|
||||
func BuildValidatorFromM2(listM2 []int64) []byte {
|
||||
var validatorBytes []byte
|
||||
for _, numberM2 := range listM2 {
|
||||
// Convert number to byte.
|
||||
m2Byte := common.LeftPadBytes([]byte(fmt.Sprintf("%d", numberM2)), M2ByteLength)
|
||||
validatorBytes = append(validatorBytes, m2Byte...)
|
||||
}
|
||||
|
||||
return validatorBytes
|
||||
}
|
||||
|
||||
// Extract validators from byte array.
|
||||
func ExtractValidatorsFromBytes(byteValidators []byte) []int64 {
|
||||
lenValidator := len(byteValidators) / M2ByteLength
|
||||
var validators []int64
|
||||
for i := 0; i < lenValidator; i++ {
|
||||
trimByte := bytes.Trim(byteValidators[i*M2ByteLength:(i+1)*M2ByteLength], "\x00")
|
||||
intNumber, err := strconv.Atoi(string(trimByte))
|
||||
if err != nil {
|
||||
log.Error("Can not convert string to integer", "error", err)
|
||||
}
|
||||
validators = append(validators, int64(intNumber))
|
||||
}
|
||||
|
||||
return validators
|
||||
}
|
||||
|
||||
// Decode validator hex string.
|
||||
func DecodeValidatorsHexData(validatorsStr string) ([]int64, error) {
|
||||
validatorsByte, err := hexutil.Decode(validatorsStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ExtractValidatorsFromBytes(validatorsByte), nil
|
||||
}
|
||||
|
||||
// Decrypt randomize from secrets and opening.
|
||||
func DecryptRandomizeFromSecretsAndOpening(secrets [][32]byte, opening [32]byte) (int64, error) {
|
||||
var random int64
|
||||
if len(secrets) > 0 {
|
||||
for _, secret := range secrets {
|
||||
trimSecret := bytes.TrimLeft(secret[:], "\x00")
|
||||
decryptSecret := Decrypt(opening[:], string(trimSecret))
|
||||
if isInt(decryptSecret) {
|
||||
intNumber, err := strconv.Atoi(decryptSecret)
|
||||
if err != nil {
|
||||
log.Error("Can not convert string to integer", "error", err)
|
||||
}
|
||||
random = int64(intNumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return random, nil
|
||||
}
|
||||
|
||||
// Calculate reward for reward checkpoint.
|
||||
func GetRewardForCheckpoint(chain consensus.ChainReader, blockSignerAddr common.Address, number uint64, rCheckpoint uint64, client bind.ContractBackend, totalSigner *uint64) (map[common.Address]*rewardLog, error) {
|
||||
// Not reward for singer of genesis block and only calculate reward at checkpoint block.
|
||||
|
|
@ -453,128 +234,4 @@ func GetRewardBalancesRate(foudationWalletAddr common.Address, masterAddr common
|
|||
log.Info("Holders reward", "holders", string(jsonHolders), "master node", masterAddr.String())
|
||||
|
||||
return balances, nil
|
||||
}
|
||||
|
||||
// Dynamic generate array sequence of numbers.
|
||||
func NewSlice(start int64, end int64, step int64) []int64 {
|
||||
s := make([]int64, end-start)
|
||||
for i := range s {
|
||||
s[i] = start
|
||||
start += step
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Shuffle array.
|
||||
func Shuffle(slice []int64) []int64 {
|
||||
newSlice := make([]int64, len(slice))
|
||||
copy(newSlice, slice)
|
||||
|
||||
for i := 0; i < len(slice)-1; i++ {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
randIndex := rand.Intn(len(newSlice))
|
||||
x := newSlice[i]
|
||||
newSlice[i] = newSlice[randIndex]
|
||||
newSlice[randIndex] = x
|
||||
}
|
||||
|
||||
return newSlice
|
||||
}
|
||||
|
||||
// encrypt string to base64 crypto using AES
|
||||
func Encrypt(key []byte, text string) string {
|
||||
// key := []byte(keyText)
|
||||
plaintext := []byte(text)
|
||||
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// The IV needs to be unique, but not secure. Therefore it's common to
|
||||
// include it at the beginning of the ciphertext.
|
||||
ciphertext := make([]byte, aes.BlockSize+len(plaintext))
|
||||
iv := ciphertext[:aes.BlockSize]
|
||||
if _, err := io.ReadFull(cryptoRand.Reader, iv); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
stream := cipher.NewCFBEncrypter(block, iv)
|
||||
stream.XORKeyStream(ciphertext[aes.BlockSize:], plaintext)
|
||||
|
||||
// convert to base64
|
||||
return base64.URLEncoding.EncodeToString(ciphertext)
|
||||
}
|
||||
|
||||
// decrypt from base64 to decrypted string
|
||||
func Decrypt(key []byte, cryptoText string) string {
|
||||
ciphertext, _ := base64.URLEncoding.DecodeString(cryptoText)
|
||||
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// The IV needs to be unique, but not secure. Therefore it's common to
|
||||
// include it at the beginning of the ciphertext.
|
||||
if len(ciphertext) < aes.BlockSize {
|
||||
panic("ciphertext too short")
|
||||
}
|
||||
iv := ciphertext[:aes.BlockSize]
|
||||
ciphertext = ciphertext[aes.BlockSize:]
|
||||
|
||||
stream := cipher.NewCFBDecrypter(block, iv)
|
||||
|
||||
// XORKeyStream can work in-place if the two arguments are the same.
|
||||
stream.XORKeyStream(ciphertext, ciphertext)
|
||||
|
||||
return fmt.Sprintf("%s", ciphertext)
|
||||
}
|
||||
|
||||
// Generate random string.
|
||||
func RandStringByte(n int) []byte {
|
||||
letterBytes := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// Helper function check string is numeric.
|
||||
func isInt(strNumber string) bool {
|
||||
if _, err := strconv.Atoi(strNumber); err == nil {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Get masternodes address from checkpoint Header.
|
||||
func GetMasternodesFromCheckpointHeader(checkpointHeader *types.Header) []common.Address {
|
||||
masternodes := make([]common.Address, (len(checkpointHeader.Extra)-extraVanity-extraSeal)/common.AddressLength)
|
||||
for i := 0; i < len(masternodes); i++ {
|
||||
copy(masternodes[i][:], checkpointHeader.Extra[extraVanity+i*common.AddressLength:])
|
||||
}
|
||||
return masternodes
|
||||
}
|
||||
|
||||
// Get m2 list from checkpoint block.
|
||||
func GetM2FromCheckpointBlock(checkpointBlock types.Block) ([]common.Address, error) {
|
||||
if checkpointBlock.Number().Int64()%EpocBlockRandomize != 0 {
|
||||
return nil, errors.New("This block is not checkpoint block epoc.")
|
||||
}
|
||||
|
||||
// Get singers from this block.
|
||||
masternodes := GetMasternodesFromCheckpointHeader(checkpointBlock.Header())
|
||||
validators := ExtractValidatorsFromBytes(checkpointBlock.Header().Validators)
|
||||
|
||||
var m2List []common.Address
|
||||
for validatorIndex := range validators {
|
||||
m2List = append(m2List, masternodes[validatorIndex])
|
||||
}
|
||||
|
||||
return m2List, nil
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package contracts
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||
|
|
@ -17,30 +16,22 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
acc1Key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
|
||||
acc2Key, _ = crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee")
|
||||
acc3Key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||
acc4Key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee04aefe388d1e14474d32c45c72ce7b7a")
|
||||
acc1Addr = crypto.PubkeyToAddress(acc1Key.PublicKey)
|
||||
acc2Addr = crypto.PubkeyToAddress(acc2Key.PublicKey)
|
||||
acc3Addr = crypto.PubkeyToAddress(acc3Key.PublicKey)
|
||||
acc4Addr = crypto.PubkeyToAddress(acc4Key.PublicKey)
|
||||
)
|
||||
|
||||
func getCommonBackend() *backends.SimulatedBackend {
|
||||
genesis := core.GenesisAlloc{acc1Addr: {Balance: big.NewInt(1000000000000)}}
|
||||
backend := backends.NewSimulatedBackend(genesis)
|
||||
backend.Commit()
|
||||
|
||||
return backend
|
||||
}
|
||||
|
||||
func TestSendTxSign(t *testing.T) {
|
||||
acc1Key, _ := crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
|
||||
acc2Key, _ := crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee")
|
||||
acc3Key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||
acc4Key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee04aefe388d1e14474d32c45c72ce7b7a")
|
||||
acc1Addr := crypto.PubkeyToAddress(acc1Key.PublicKey)
|
||||
acc2Addr := crypto.PubkeyToAddress(acc2Key.PublicKey)
|
||||
acc3Addr := crypto.PubkeyToAddress(acc3Key.PublicKey)
|
||||
acc4Addr := crypto.PubkeyToAddress(acc4Key.PublicKey)
|
||||
accounts := []common.Address{acc2Addr, acc3Addr, acc4Addr}
|
||||
keys := []*ecdsa.PrivateKey{acc2Key, acc3Key, acc4Key}
|
||||
backend := getCommonBackend()
|
||||
|
||||
signer := types.HomesteadSigner{}
|
||||
genesis := core.GenesisAlloc{acc1Addr: {Balance: big.NewInt(1000000000)}}
|
||||
backend := backends.NewSimulatedBackend(genesis)
|
||||
backend.Commit()
|
||||
ctx := context.Background()
|
||||
|
||||
transactOpts := bind.NewKeyedTransactor(acc1Key)
|
||||
|
|
@ -108,88 +99,4 @@ func randomHash() common.Hash {
|
|||
b[i] = letterBytes[rand.Intn(len(letterBytes))]
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// Unit test for get random position of masternodes.
|
||||
func TestRandomMasterNode(t *testing.T) {
|
||||
oldSlice := NewSlice(0, 10, 1)
|
||||
newSlice := Shuffle(oldSlice)
|
||||
for _, newNumber := range newSlice {
|
||||
for i, oldNumber := range oldSlice {
|
||||
if oldNumber == newNumber {
|
||||
// Delete find element.
|
||||
oldSlice = append(oldSlice[:i], oldSlice[i+1:]...)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(oldSlice) != 0 {
|
||||
t.Errorf("Test generate random masternode fail %v - %v", oldSlice, newSlice)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncryptDecrypt(t *testing.T) {
|
||||
//byteInteger := common.LeftPadBytes([]byte(new(big.Int).SetInt64(4).String()), 32)
|
||||
randomByte := RandStringByte(32)
|
||||
encrypt := Encrypt(randomByte, new(big.Int).SetInt64(4).String())
|
||||
decrypt := Decrypt(randomByte, encrypt)
|
||||
t.Log("Encrypt", encrypt, "Test", string(randomByte), "Decrypt", decrypt, "trim", string(bytes.TrimLeft([]byte(decrypt), "\x00")))
|
||||
}
|
||||
|
||||
func isArrayEqual(a [][]int64, b [][]int64) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i, vs := range a {
|
||||
for j, v := range vs {
|
||||
if v != b[i][j] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Unit test for
|
||||
func TestGenM2FromRandomize(t *testing.T) {
|
||||
var a []int64
|
||||
for i := 0; i <= 10; i++ {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
a = append(a, int64(rand.Intn(9999)))
|
||||
}
|
||||
b, err := GenM2FromRandomize(a)
|
||||
t.Log("randomize", b, "len", len(b))
|
||||
if err != nil {
|
||||
t.Error("Fail to test gen m2 for randomize.", err)
|
||||
}
|
||||
// Test Permutation Without Fixed-point.
|
||||
M1List := NewSlice(int64(0), MaxMasternodes, 1)
|
||||
for i, m1 := range M1List {
|
||||
if m1 == b[i] {
|
||||
t.Errorf("Error check Permutation Without Fixed-point %v - %v - %v", i, b[i], a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unit test for validator m2.
|
||||
func TestBuildValidatorFromM2(t *testing.T) {
|
||||
a := []int64{84, 58, 27, 96, 127, 60, 136, 20, 121, 31, 87, 85, 40, 120, 149, 109, 141, 145, 11, 110, 147, 35, 76, 46, 34, 108, 72, 103, 102, 12, 23, 47, 70, 86, 125, 112, 128, 13, 130, 98, 126, 62, 132, 111, 134, 6, 106, 67, 24, 91, 101, 50, 94, 43, 77, 73, 129, 71, 51, 10, 92, 29, 80, 95, 33, 100, 124, 75, 38, 133, 79, 83, 61, 36, 122, 99, 16, 28, 18, 116, 140, 97, 119, 82, 148, 48, 56, 32, 93, 107, 69, 68, 123, 81, 22, 137, 25, 115, 44, 8, 42, 131, 143, 17, 55, 89, 9, 15, 19, 59, 146, 54, 5, 30, 41, 144, 117, 1, 104, 49, 105, 45, 88, 78, 74, 135, 0, 21, 57, 3, 66, 52, 63, 138, 4, 114, 37, 118, 14, 2, 26, 7, 65, 139, 39, 64, 90, 142, 53, 113}
|
||||
b := BuildValidatorFromM2(a)
|
||||
c := ExtractValidatorsFromBytes(b)
|
||||
if !isArrayEqual([][]int64{a}, [][]int64{c}) {
|
||||
t.Errorf("Fail to get m2 result %v", b)
|
||||
}
|
||||
}
|
||||
|
||||
// Unit test for decode validator string data.
|
||||
func TestDecodeValidatorsHexData(t *testing.T) {
|
||||
a := "0x000000310000003000000032000000310000003000000032000000310000003000000032000000310000003000000031000000320000003000000031000000320000003000000031000000320000003000000030000000310000003200000030000000310000003200000030000000310000003200000030000000300000003100000032000000300000003100000032000000300000003100000032000000300000003200000030000000310000003200000030000000310000003200000030000000310000003000000030"
|
||||
b, err := DecodeValidatorsHexData(a)
|
||||
if err != nil {
|
||||
t.Error("Fail to decode validator from hex string", err)
|
||||
}
|
||||
c := []int64{1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 2, 0, 1, 2, 0, 1, 2, 0, 1, 0, 0}
|
||||
if !isArrayEqual([][]int64{b}, [][]int64{c}) {
|
||||
t.Errorf("Fail to get m2 result %v", b)
|
||||
}
|
||||
t.Log("b", b)
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ func TestDefaultGenesisBlock(t *testing.T) {
|
|||
|
||||
func TestSetupGenesis(t *testing.T) {
|
||||
var (
|
||||
customghash = common.HexToHash("0xa1cd36b0c6db6940b1184a28cea11f4f74d823589c6a7e7f1398a5c176835598")
|
||||
customghash = common.HexToHash("0x89c99d90b79719238d2645c7642f2c9295246e80775b38cfd162b696817fbd50")
|
||||
customg = Genesis{
|
||||
Config: ¶ms.ChainConfig{HomesteadBlock: big.NewInt(3)},
|
||||
Alloc: GenesisAlloc{
|
||||
|
|
|
|||
|
|
@ -251,19 +251,15 @@ func (l *txList) Overlaps(tx *types.Transaction) bool {
|
|||
func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Transaction) {
|
||||
// If there's an older better transaction, abort
|
||||
old := l.txs.Get(tx.Nonce())
|
||||
|
||||
if (tx.To() != nil && tx.To().String() != common.RandomizeSMC) || tx.To() == nil {
|
||||
if old != nil {
|
||||
threshold := new(big.Int).Div(new(big.Int).Mul(old.GasPrice(), big.NewInt(100+int64(priceBump))), big.NewInt(100))
|
||||
// Have to ensure that the new gas price is higher than the old gas
|
||||
// price as well as checking the percentage threshold to ensure that
|
||||
// this is accurate for low (Wei-level) gas price replacements
|
||||
if old.GasPrice().Cmp(tx.GasPrice()) >= 0 || threshold.Cmp(tx.GasPrice()) > 0 {
|
||||
return false, nil
|
||||
}
|
||||
if old != nil {
|
||||
threshold := new(big.Int).Div(new(big.Int).Mul(old.GasPrice(), big.NewInt(100+int64(priceBump))), big.NewInt(100))
|
||||
// Have to ensure that the new gas price is higher than the old gas
|
||||
// price as well as checking the percentage threshold to ensure that
|
||||
// this is accurate for low (Wei-level) gas price replacements
|
||||
if old.GasPrice().Cmp(tx.GasPrice()) >= 0 || threshold.Cmp(tx.GasPrice()) > 0 {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise overwrite the old transaction with the current one
|
||||
l.txs.Put(tx)
|
||||
if cost := tx.Cost(); l.costcap.Cmp(cost) < 0 {
|
||||
|
|
|
|||
|
|
@ -589,7 +589,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
|||
return ErrInsufficientFunds
|
||||
}
|
||||
|
||||
if tx.To() != nil && tx.To().String() != common.BlockSigners && tx.To().String() != common.RandomizeSMC {
|
||||
if tx.To() == nil || (tx.To() != nil && tx.To().String() != common.BlockSigners) {
|
||||
intrGas, err := IntrinsicGas(tx.Data(), tx.To() == nil, pool.homestead)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -17,19 +17,19 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
||||
// from bcValidBlockTest.json, "SimpleTx"
|
||||
func TestBlockEncoding(t *testing.T) {
|
||||
blockEnc := common.FromHex("f90261f901faa00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a05fe50b260da6308036625b850b5d6ced6d0a9f814c0688bc91ffb7b7a3a54b67a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8825208845506eb0780a0bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff49888a13a5a8c8f2bb1c480f861f85f800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba09bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094fa08a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b1c0")
|
||||
blockEnc := common.FromHex("f90260f901f9a083cafc574e1f51ba9dc0568fc617a08ea2429fb384059c972f13b19fa1c8dd55a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a05fe50b260da6308036625b850b5d6ced6d0a9f814c0688bc91ffb7b7a3a54b67a0bc37d79753ad738a6dac4921e57392f145d8887476de3f783dfa7edae9283e52b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd8825208845506eb0780a0bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff49888a13a5a8c8f2bb1c4f861f85f800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba09bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094fa08a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b1c0")
|
||||
var block Block
|
||||
if err := rlp.DecodeBytes(blockEnc, &block); err != nil {
|
||||
t.Fatal("decode error: ", err)
|
||||
|
|
@ -46,7 +46,7 @@ func TestBlockEncoding(t *testing.T) {
|
|||
check("Coinbase", block.Coinbase(), common.HexToAddress("8888f1f195afa192cfee860698584c030f4c9db1"))
|
||||
check("MixDigest", block.MixDigest(), common.HexToHash("bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff498"))
|
||||
check("Root", block.Root(), common.HexToHash("ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017"))
|
||||
check("Hash", block.Hash(), common.HexToHash("ed8e5b071b309a4c965a2b4aabd1f8f7818276627331ca37e753a3e97ec87081"))
|
||||
check("Hash", block.Hash(), common.HexToHash("0a5843ac1cb04865017cb35a57b50b07084e5fcee39b5acadade33149f4fff9e"))
|
||||
check("Nonce", block.Nonce(), uint64(0xa13a5a8c8f2bb1c4))
|
||||
check("Time", block.Time(), big.NewInt(1426516743))
|
||||
check("Size", block.Size(), common.StorageSize(len(blockEnc)))
|
||||
|
|
@ -64,8 +64,7 @@ func TestBlockEncoding(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal("encode error: ", err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(ourBlockEnc, blockEnc) {
|
||||
t.Errorf("encoded block mismatch:\ngot: %x\nwant: %x", ourBlockEnc, blockEnc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
|||
return
|
||||
}
|
||||
if _, authorized := snap.Signers[eth.etherbase]; authorized {
|
||||
if err := contracts.CreateTransactionSign(chainConfig, eth.txPool, eth.accountManager, block, chainDb); err != nil {
|
||||
if err := contracts.CreateTransactionSign(chainConfig, eth.txPool, eth.accountManager, block); err != nil {
|
||||
log.Error("Fail to create tx sign for imported block", "error", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -251,39 +251,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check m2 exists on chaindb.
|
||||
// Get secrets and opening at epoc block checkpoint.
|
||||
if number > 0 && number%contracts.EpocBlockRandomize == 0 {
|
||||
var candidates []int64
|
||||
// Get signers from snapshot.
|
||||
snap, err := c.GetSnapshot(eth.blockchain, chain.CurrentHeader())
|
||||
if err != nil {
|
||||
log.Error("Fail to get snapshot for get secret and opening.", "error", err)
|
||||
return err
|
||||
}
|
||||
signers := snap.Signers
|
||||
|
||||
if len(signers) > 0 {
|
||||
for addr := range signers {
|
||||
random, err := contracts.GetRandomizeFromContract(client, addr)
|
||||
if err != nil {
|
||||
log.Error("Fail to get random m2 from contract.", "error", err)
|
||||
}
|
||||
candidates = append(candidates, random)
|
||||
}
|
||||
}
|
||||
|
||||
// Get randomize m2 list.
|
||||
m2, err := contracts.GenM2FromRandomize(candidates)
|
||||
if err != nil {
|
||||
log.Error("Can not get m2 from randomize SC", "error", err)
|
||||
}
|
||||
if len(m2) > 0 {
|
||||
header.Validators = contracts.BuildValidatorFromM2(m2)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
eth/tracers/testdata/call_tracer_create.json
vendored
2
eth/tracers/testdata/call_tracer_create.json
vendored
|
|
@ -26,7 +26,7 @@
|
|||
"chainId": 3,
|
||||
"daoForkSupport": true,
|
||||
"eip150Block": 0,
|
||||
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
|
||||
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
|
||||
"eip155Block": 10,
|
||||
"eip158Block": 10,
|
||||
"ethash": {},
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@
|
|||
"chainId": 3,
|
||||
"daoForkSupport": true,
|
||||
"eip150Block": 0,
|
||||
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
|
||||
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
|
||||
"eip155Block": 10,
|
||||
"eip158Block": 10,
|
||||
"ethash": {},
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
"chainId": 3,
|
||||
"daoForkSupport": true,
|
||||
"eip150Block": 0,
|
||||
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
|
||||
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
|
||||
"eip155Block": 10,
|
||||
"eip158Block": 10,
|
||||
"ethash": {},
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
"chainId": 3,
|
||||
"daoForkSupport": true,
|
||||
"eip150Block": 0,
|
||||
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
|
||||
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
|
||||
"eip155Block": 10,
|
||||
"eip158Block": 10,
|
||||
"ethash": {},
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
"chainId": 3,
|
||||
"daoForkSupport": true,
|
||||
"eip150Block": 0,
|
||||
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
|
||||
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
|
||||
"eip155Block": 10,
|
||||
"eip158Block": 10,
|
||||
"ethash": {},
|
||||
|
|
|
|||
2
eth/tracers/testdata/call_tracer_oog.json
vendored
2
eth/tracers/testdata/call_tracer_oog.json
vendored
|
|
@ -28,7 +28,7 @@
|
|||
"chainId": 3,
|
||||
"daoForkSupport": true,
|
||||
"eip150Block": 0,
|
||||
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
|
||||
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
|
||||
"eip155Block": 10,
|
||||
"eip158Block": 10,
|
||||
"ethash": {},
|
||||
|
|
|
|||
2
eth/tracers/testdata/call_tracer_revert.json
vendored
2
eth/tracers/testdata/call_tracer_revert.json
vendored
|
|
@ -26,7 +26,7 @@
|
|||
"chainId": 3,
|
||||
"daoForkSupport": true,
|
||||
"eip150Block": 0,
|
||||
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
|
||||
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
|
||||
"eip155Block": 10,
|
||||
"eip158Block": 10,
|
||||
"ethash": {},
|
||||
|
|
|
|||
2
eth/tracers/testdata/call_tracer_simple.json
vendored
2
eth/tracers/testdata/call_tracer_simple.json
vendored
|
|
@ -37,7 +37,7 @@
|
|||
"chainId": 3,
|
||||
"daoForkSupport": true,
|
||||
"eip150Block": 0,
|
||||
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
|
||||
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
|
||||
"eip155Block": 10,
|
||||
"eip158Block": 10,
|
||||
"ethash": {},
|
||||
|
|
|
|||
2
eth/tracers/testdata/call_tracer_throw.json
vendored
2
eth/tracers/testdata/call_tracer_throw.json
vendored
|
|
@ -30,7 +30,7 @@
|
|||
"chainId": 3,
|
||||
"daoForkSupport": true,
|
||||
"eip150Block": 0,
|
||||
"eip150Hash": "0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a",
|
||||
"eip150Hash": "0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d",
|
||||
"eip155Block": 10,
|
||||
"eip158Block": 10,
|
||||
"ethash": {},
|
||||
|
|
|
|||
|
|
@ -816,7 +816,6 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
|
|||
"timestamp": (*hexutil.Big)(head.Time),
|
||||
"transactionsRoot": head.TxHash,
|
||||
"receiptsRoot": head.ReceiptHash,
|
||||
"validators": hexutil.Bytes(head.Validators),
|
||||
}
|
||||
|
||||
if inclTx {
|
||||
|
|
|
|||
|
|
@ -364,7 +364,7 @@ func (self *worker) wait() {
|
|||
}
|
||||
}
|
||||
// Send tx sign to smart contract blockSigners.
|
||||
if err := contracts.CreateTransactionSign(self.config, self.eth.TxPool(), self.eth.AccountManager(), block, self.chainDb); err != nil {
|
||||
if err := contracts.CreateTransactionSign(self.config, self.eth.TxPool(), self.eth.AccountManager(), block); err != nil {
|
||||
log.Error("Fail to create tx sign for signer", "error", "err")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
MainnetGenesisHash = common.HexToHash("2efa267fef46877ac2659209e2299f97b0afc2a797ee8672db21920a5151e0aa") // Mainnet genesis hash to enforce below configs on
|
||||
TestnetGenesisHash = common.HexToHash("fc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a") // Testnet genesis hash to enforce below configs on
|
||||
MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3") // Mainnet genesis hash to enforce below configs on
|
||||
TestnetGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d") // Testnet genesis hash to enforce below configs on
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -51,7 +51,7 @@ var (
|
|||
DAOForkBlock: nil,
|
||||
DAOForkSupport: true,
|
||||
EIP150Block: big.NewInt(0),
|
||||
EIP150Hash: common.HexToHash("0xfc673c99f7650df67bf769ab5b923ef60deefdbb49a6fe0dea14420f6790736a"),
|
||||
EIP150Hash: common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"),
|
||||
EIP155Block: big.NewInt(10),
|
||||
EIP158Block: big.NewInt(10),
|
||||
ByzantiumBlock: big.NewInt(1700000),
|
||||
|
|
|
|||
Loading…
Reference in a new issue