zfliex924 преди 3 години
родител
ревизия
82718869a8

+ 3 - 3
accounts/accounts.go

@@ -38,9 +38,9 @@ type Account struct {
 const (
 	MimetypeDataWithValidator = "data/validator"
 	MimetypeTypedData         = "data/typed"
-	MimetypeClique    = "application/x-clique-header"
-	MimetypeSatoshi   = "application/x-satoshi-header"
-	MimetypeTextPlain = "text/plain"
+	MimetypeClique            = "application/x-clique-header"
+	MimetypeSatoshi           = "application/x-satoshi-header"
+	MimetypeTextPlain         = "text/plain"
 )
 
 // Wallet represents a software or hardware wallet that might contain one or more

+ 13 - 13
cmd/faucet/faucet.go

@@ -92,7 +92,7 @@ var (
 )
 
 var (
-	ether        = new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)
+	ether = new(big.Int).Exp(big.NewInt(10), big.NewInt(18), nil)
 )
 
 var (
@@ -139,11 +139,11 @@ func main() {
 	}
 	website := new(bytes.Buffer)
 	err = template.Must(template.New("").Parse(string(tmpl))).Execute(website, map[string]interface{}{
-		"Network":    *netnameFlag,
-		"Amounts":    amounts,
+		"Network":   *netnameFlag,
+		"Amounts":   amounts,
 		"Periods":   periods,
-		"Recaptcha":  *captchaToken,
-		"NoAuth":     *noauthFlag,
+		"Recaptcha": *captchaToken,
+		"NoAuth":    *noauthFlag,
 	})
 	if err != nil {
 		log.Crit("Failed to render the faucet template", "err", err)
@@ -285,14 +285,14 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*enode.Node, network ui
 	client := ethclient.NewClient(api)
 
 	return &faucet{
-		config:     genesis.Config,
-		stack:      stack,
-		client:     client,
-		index:      index,
-		keystore:   ks,
-		account:    ks.Accounts()[0],
-		timeouts:   make(map[string]time.Time),
-		update:     make(chan struct{}, 1),
+		config:   genesis.Config,
+		stack:    stack,
+		client:   client,
+		index:    index,
+		keystore: ks,
+		account:  ks.Accounts()[0],
+		timeouts: make(map[string]time.Time),
+		update:   make(chan struct{}, 1),
 	}, nil
 }
 

+ 19 - 21
consensus/satoshi/satoshi.go

@@ -48,7 +48,7 @@ const (
 
 	checkpointInterval   = 1024        // Number of blocks after which to save the snapshot to the database
 	defaultEpochLength   = uint64(100) // Default number of blocks of checkpoint to update validatorSet from contract
-    defaultRoundInterval = 86400       // Default number of seconds to turn round
+	defaultRoundInterval = 86400       // Default number of seconds to turn round
 
 	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
@@ -65,20 +65,18 @@ var (
 	uncleHash       = types.CalcUncleHash(nil) // Always Keccak256(RLP([])) as uncles are meaningless outside of PoW.
 	diffInTurn      = big.NewInt(2)            // Block difficulty for in-turn signatures
 	diffNoTurn      = big.NewInt(1)            // Block difficulty for out-of-turn signatures
-	// 100 native token
-	maxSystemBalance = new(big.Int).Mul(big.NewInt(100), big.NewInt(params.Ether))
 
 	systemContracts = map[common.Address]bool{
-		common.HexToAddress(systemcontracts.ValidatorContract):          true,
-		common.HexToAddress(systemcontracts.SlashContract):              true,
-		common.HexToAddress(systemcontracts.SystemRewardContract):       true,
-		common.HexToAddress(systemcontracts.LightClientContract):        true,
-		common.HexToAddress(systemcontracts.RelayerHubContract):         true,
-		common.HexToAddress(systemcontracts.CandidateHubContract):       true,
-		common.HexToAddress(systemcontracts.GovHubContract):             true,
-		common.HexToAddress(systemcontracts.PledgeCandidateContract):    true,
-		common.HexToAddress(systemcontracts.BurnContract):               true,
-		common.HexToAddress(systemcontracts.FoundationContract):         true,
+		common.HexToAddress(systemcontracts.ValidatorContract):       true,
+		common.HexToAddress(systemcontracts.SlashContract):           true,
+		common.HexToAddress(systemcontracts.SystemRewardContract):    true,
+		common.HexToAddress(systemcontracts.LightClientContract):     true,
+		common.HexToAddress(systemcontracts.RelayerHubContract):      true,
+		common.HexToAddress(systemcontracts.CandidateHubContract):    true,
+		common.HexToAddress(systemcontracts.GovHubContract):          true,
+		common.HexToAddress(systemcontracts.PledgeCandidateContract): true,
+		common.HexToAddress(systemcontracts.BurnContract):            true,
+		common.HexToAddress(systemcontracts.FoundationContract):      true,
 	}
 )
 
@@ -673,7 +671,7 @@ func (p *Satoshi) BeforeValidateTx(chain consensus.ChainHeaderReader, header *ty
 }
 
 func (p *Satoshi) BeforePackTx(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB,
-	txs *[]*types.Transaction, uncles []*types.Header, receipts *[]*types.Receipt) (err error)  {
+	txs *[]*types.Transaction, uncles []*types.Header, receipts *[]*types.Receipt) (err error) {
 	cx := chainContext{Chain: chain, satoshi: p}
 	// If the block is the last one in a round, execute turn round to update the validator set.
 	if p.isRoundEnd(chain, header) {
@@ -1034,13 +1032,13 @@ func (p *Satoshi) Close() error {
 
 func (p *Satoshi) IsRoundEnd(chain consensus.ChainHeaderReader, header *types.Header) bool {
 	number := header.Number.Uint64()
-	snapshot, _ := p.snapshot(chain, number - 1, header.ParentHash, nil)
+	snapshot, _ := p.snapshot(chain, number-1, header.ParentHash, nil)
 	if snapshot == nil {
 		return true
 	}
 	if number > 0 && number%snapshot.config.Epoch == uint64(len(snapshot.Validators)/2) {
 		// find the header of last block in the previous round
-		checkHeader := FindAncientHeader(header, uint64(len(snapshot.Validators)/2) + 1, chain, nil)
+		checkHeader := FindAncientHeader(header, uint64(len(snapshot.Validators)/2)+1, chain, nil)
 		if checkHeader != nil {
 			return p.isRoundEnd(chain, checkHeader)
 		}
@@ -1132,13 +1130,13 @@ func (p *Satoshi) turnRound(state *state.StateDB, header *types.Header, chain co
 	method := "turnRound"
 
 	// get packed data
-	data, err := p.candidateHubABI.Pack(method,)
+	data, err := p.candidateHubABI.Pack(method)
 	if err != nil {
 		log.Error("Unable to pack tx for turnRound", "error", err)
 		return err
 	}
 	// get system message
-	msg := p.getSystemMessage(header.Coinbase, common.HexToAddress(systemcontracts.CandidateHubContract), header.GasLimit - params.SystemTxsGas,data, common.Big0)
+	msg := p.getSystemMessage(header.Coinbase, common.HexToAddress(systemcontracts.CandidateHubContract), header.GasLimit-params.SystemTxsGas, data, common.Big0)
 	// apply message
 	return p.applyTransaction(msg, state, header, chain, txs, receipts, receivedTxs, usedGas, mining)
 }
@@ -1281,13 +1279,13 @@ func (p *Satoshi) applyTransaction(
 // isRoundEnd returns true if the given header belongs to the last block of the round, otherwise false
 func (p *Satoshi) isRoundEnd(chain consensus.ChainHeaderReader, header *types.Header) bool {
 	number := header.Number.Uint64()
-	if number % p.config.Epoch == p.config.Epoch - 1 {
+	if number%p.config.Epoch == p.config.Epoch-1 {
 		lastCheckNumber := uint64(1)
 		if number > p.config.Epoch {
 			lastCheckNumber = number - p.config.Epoch
-		}	
+		}
 		lastCheckBlock := chain.GetHeaderByNumber(lastCheckNumber)
-		if header.Time / p.config.Round > lastCheckBlock.Time / p.config.Round {
+		if header.Time/p.config.Round > lastCheckBlock.Time/p.config.Round {
 			return true
 		}
 	}

+ 1 - 1
core/state_processor.go

@@ -427,7 +427,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
 			if isSystemTx, _ := posa.IsSystemTransaction(tx, block.Header()); isSystemTx {
 				continue
 			}
-		} 
+		}
 		msg, err := tx.AsMessage(signer)
 		if err != nil {
 			return statedb, nil, nil, 0, err

+ 10 - 10
core/systemcontracts/const.go

@@ -2,14 +2,14 @@ package systemcontracts
 
 const (
 	// genesis contracts
-	ValidatorContract          = "0x0000000000000000000000000000000000001000"
-	SlashContract              = "0x0000000000000000000000000000000000001001"
-	SystemRewardContract       = "0x0000000000000000000000000000000000001002"
-	LightClientContract        = "0x0000000000000000000000000000000000001003"
-	RelayerHubContract         = "0x0000000000000000000000000000000000001004"
-	CandidateHubContract       = "0x0000000000000000000000000000000000001005"
-	GovHubContract             = "0x0000000000000000000000000000000000001006"
-	PledgeCandidateContract    = "0x0000000000000000000000000000000000001007"
-	BurnContract               = "0x0000000000000000000000000000000000001008"
-	FoundationContract         = "0x0000000000000000000000000000000000001009"
+	ValidatorContract       = "0x0000000000000000000000000000000000001000"
+	SlashContract           = "0x0000000000000000000000000000000000001001"
+	SystemRewardContract    = "0x0000000000000000000000000000000000001002"
+	LightClientContract     = "0x0000000000000000000000000000000000001003"
+	RelayerHubContract      = "0x0000000000000000000000000000000000001004"
+	CandidateHubContract    = "0x0000000000000000000000000000000000001005"
+	GovHubContract          = "0x0000000000000000000000000000000000001006"
+	PledgeCandidateContract = "0x0000000000000000000000000000000000001007"
+	BurnContract            = "0x0000000000000000000000000000000000001008"
+	FoundationContract      = "0x0000000000000000000000000000000000001009"
 )

+ 28 - 32
core/systemcontracts/upgrade.go

@@ -1,13 +1,10 @@
 package systemcontracts
 
 import (
-	"encoding/hex"
-	"fmt"
 	"math/big"
 
 	"github.com/ethereum/go-ethereum/common"
 	"github.com/ethereum/go-ethereum/core/state"
-	"github.com/ethereum/go-ethereum/log"
 	"github.com/ethereum/go-ethereum/params"
 )
 
@@ -26,8 +23,7 @@ type Upgrade struct {
 
 type upgradeHook func(blockNumber *big.Int, contractAddr common.Address, statedb *state.StateDB) error
 
-const (
-)
+const ()
 
 var (
 	GenesisHash common.Hash
@@ -42,34 +38,34 @@ func UpgradeBuildInSystemContract(config *params.ChainConfig, blockNumber *big.I
 	*/
 }
 
-func applySystemContractUpgrade(upgrade *Upgrade, blockNumber *big.Int, statedb *state.StateDB, logger log.Logger) {
-	if upgrade == nil {
-		logger.Info("Empty upgrade config", "height", blockNumber.String())
-		return
-	}
+// func applySystemContractUpgrade(upgrade *Upgrade, blockNumber *big.Int, statedb *state.StateDB, logger log.Logger) {
+// 	if upgrade == nil {
+// 		logger.Info("Empty upgrade config", "height", blockNumber.String())
+// 		return
+// 	}
 
-	logger.Info(fmt.Sprintf("Apply upgrade %s at height %d", upgrade.UpgradeName, blockNumber.Int64()))
-	for _, cfg := range upgrade.Configs {
-		logger.Info(fmt.Sprintf("Upgrade contract %s to commit %s", cfg.ContractAddr.String(), cfg.CommitUrl))
+// 	logger.Info(fmt.Sprintf("Apply upgrade %s at height %d", upgrade.UpgradeName, blockNumber.Int64()))
+// 	for _, cfg := range upgrade.Configs {
+// 		logger.Info(fmt.Sprintf("Upgrade contract %s to commit %s", cfg.ContractAddr.String(), cfg.CommitUrl))
 
-		if cfg.BeforeUpgrade != nil {
-			err := cfg.BeforeUpgrade(blockNumber, cfg.ContractAddr, statedb)
-			if err != nil {
-				panic(fmt.Errorf("contract address: %s, execute beforeUpgrade error: %s", cfg.ContractAddr.String(), err.Error()))
-			}
-		}
+// 		if cfg.BeforeUpgrade != nil {
+// 			err := cfg.BeforeUpgrade(blockNumber, cfg.ContractAddr, statedb)
+// 			if err != nil {
+// 				panic(fmt.Errorf("contract address: %s, execute beforeUpgrade error: %s", cfg.ContractAddr.String(), err.Error()))
+// 			}
+// 		}
 
-		newContractCode, err := hex.DecodeString(cfg.Code)
-		if err != nil {
-			panic(fmt.Errorf("failed to decode new contract code: %s", err.Error()))
-		}
-		statedb.SetCode(cfg.ContractAddr, newContractCode)
+// 		newContractCode, err := hex.DecodeString(cfg.Code)
+// 		if err != nil {
+// 			panic(fmt.Errorf("failed to decode new contract code: %s", err.Error()))
+// 		}
+// 		statedb.SetCode(cfg.ContractAddr, newContractCode)
 
-		if cfg.AfterUpgrade != nil {
-			err := cfg.AfterUpgrade(blockNumber, cfg.ContractAddr, statedb)
-			if err != nil {
-				panic(fmt.Errorf("contract address: %s, execute afterUpgrade error: %s", cfg.ContractAddr.String(), err.Error()))
-			}
-		}
-	}
-}
+// 		if cfg.AfterUpgrade != nil {
+// 			err := cfg.AfterUpgrade(blockNumber, cfg.ContractAddr, statedb)
+// 			if err != nil {
+// 				panic(fmt.Errorf("contract address: %s, execute afterUpgrade error: %s", cfg.ContractAddr.String(), err.Error()))
+// 			}
+// 		}
+// 	}
+// }

+ 6 - 5
core/vm/contracts_lightclient.go

@@ -4,9 +4,10 @@ import (
 	"bytes"
 	"encoding/binary"
 	"fmt"
+
+	"github.com/coredao-org/btcpowermirror/lightmirror"
 	"github.com/ethereum/go-ethereum/common"
 	"github.com/ethereum/go-ethereum/params"
-	"github.com/coredao-org/btcpowermirror/lightmirror"
 )
 
 const (
@@ -38,7 +39,7 @@ func (c *btcValidate) Run(input []byte) (result []byte, err error) {
 	}
 
 	rbuf := bytes.NewReader(input[precompileContractInputMetaDataLength:])
-	var mirror lightmirror.BtcLightMirror;
+	var mirror lightmirror.BtcLightMirror
 	err = mirror.Deserialize(rbuf)
 	if err != nil {
 		err = fmt.Errorf("deserialize btcLightMirror failed %s", err.Error())
@@ -46,7 +47,7 @@ func (c *btcValidate) Run(input []byte) (result []byte, err error) {
 	}
 
 	// Verify MerkleRoot & coinbaseTx
-	err = mirror.CheckMerkle();
+	err = mirror.CheckMerkle()
 	if err != nil {
 		err = fmt.Errorf("verify btcLightMirror failed %s", err.Error())
 		return nil, err
@@ -57,7 +58,7 @@ func (c *btcValidate) Run(input []byte) (result []byte, err error) {
 	// | coinbaseAddr        |
 	// | 20 bytes + 12 bytes |
 	addrTypeBytes := make([]byte, 4)
-	binary.BigEndian.PutUint32(addrTypeBytes,(uint32)(addrType))
+	binary.BigEndian.PutUint32(addrTypeBytes, (uint32)(addrType))
 	addrTypeBytes = common.LeftPadBytes(addrTypeBytes[:], 32)
-	return append(common.RightPadBytes(coinbaseAddr[:], 32),addrTypeBytes...) , nil
+	return append(common.RightPadBytes(coinbaseAddr[:], 32), addrTypeBytes...), nil
 }

+ 3 - 1
core/vm/contracts_lightclient_test.go

@@ -3,9 +3,11 @@ package vm
 import (
 	"encoding/binary"
 	"encoding/hex"
-	"testing"
+
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
+
+	"testing"
 )
 
 func TestGetMinerAndMerkleProofValidate(t *testing.T) {

+ 2 - 2
params/config.go

@@ -35,7 +35,7 @@ var (
 	CoreGenesisHash    = common.HexToHash("0x0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b")
 	BuffaloGenesisHash = common.HexToHash("0x6d3c66c5357ec91d5c43af47e234a939b22557cbb552dc45bebbceeed90fbe34")
 	RialtoGenesisHash  = common.HexToHash("0x005dc005bddd1967de6187c1c23be801eb7abdd80cebcc24f341b727b70311d6")
-	YoloV3GenesisHash = common.HexToHash("0xf1f2876e8500c77afcc03228757b39477eceffccf645b734967fe3c7e16967b7")
+	YoloV3GenesisHash  = common.HexToHash("0xf1f2876e8500c77afcc03228757b39477eceffccf645b734967fe3c7e16967b7")
 )
 
 // TrustedCheckpoints associates each known checkpoint with the genesis hash of
@@ -392,7 +392,7 @@ type ChainConfig struct {
 	CatalystBlock *big.Int `json:"catalystBlock,omitempty"` // Catalyst switch block (nil = no fork, 0 = already on catalyst)
 
 	// Various consensus engines
-	Ethash *EthashConfig `json:"ethash,omitempty" toml:",omitempty"`
+	Ethash  *EthashConfig  `json:"ethash,omitempty" toml:",omitempty"`
 	Clique  *CliqueConfig  `json:"clique,omitempty" toml:",omitempty"`
 	Satoshi *SatoshiConfig `json:"satoshi,omitempty" toml:",omitempty"`
 }

+ 1 - 1
params/protocol_params.go

@@ -116,7 +116,7 @@ const (
 
 	//TODO need further discussion
 	BitcoinHeaderValidateGas   uint64 = 20000 // Gas for validate bitcoin consensus state
-	IAVLMerkleProofValidateGas uint64 = 100 // Gas for validate merkle proof
+	IAVLMerkleProofValidateGas uint64 = 100   // Gas for validate merkle proof
 
 	EcrecoverGas        uint64 = 3000 // Elliptic curve sender recovery gas price
 	Sha256BaseGas       uint64 = 60   // Base price for a SHA256 operation