OSDN Git Service

genesis is ready for mainnet
authorpaladz <453256728@qq.com>
Sat, 21 Apr 2018 16:29:24 +0000 (00:29 +0800)
committerpaladz <453256728@qq.com>
Sat, 21 Apr 2018 16:29:24 +0000 (00:29 +0800)
config/genesis.go
config/genesis_test.go
consensus/general.go
database/leveldb/store_test.go
protocol/block_test.go
protocol/protocol.go
wallet/wallet.go

index f7912c1..d08d8b5 100644 (file)
@@ -1,6 +1,8 @@
 package config
 
 import (
+       "encoding/hex"
+
        log "github.com/sirupsen/logrus"
 
        "github.com/bytom/consensus"
@@ -8,60 +10,52 @@ import (
        "github.com/bytom/protocol/bc/types"
 )
 
-// GenerateGenesisTx will return genesis transaction
-func GenerateGenesisTx() *types.Tx {
+func genesisTx() *types.Tx {
+       contract, err := hex.DecodeString("00149514bf92cac8791dcc4cd7fd3ef4167ffc477f62")
+       if err != nil {
+               log.Panicf("fail on decode genesis tx output control program")
+       }
+
        txData := types.TxData{
-               Version:        1,
-               SerializedSize: 63,
+               Version: 1,
                Inputs: []*types.TxInput{
                        types.NewCoinbaseInput([]byte("May 4th Be With You")),
                },
                Outputs: []*types.TxOutput{
-                       &types.TxOutput{
-                               AssetVersion: 1,
-                               OutputCommitment: types.OutputCommitment{
-                                       AssetAmount: bc.AssetAmount{
-                                               AssetId: consensus.BTMAssetID,
-                                               Amount:  consensus.InitialBlockSubsidy,
-                                       },
-                                       VMVersion:      1,
-                                       ControlProgram: []byte{81},
-                               },
-                       },
+                       types.NewTxOutput(*consensus.BTMAssetID, consensus.InitialBlockSubsidy, contract),
                },
        }
-
        return types.NewTx(txData)
 }
 
-// GenerateGenesisBlock will return genesis block
-func GenerateGenesisBlock() *types.Block {
-       genesisCoinbaseTx := GenerateGenesisTx()
-       merkleRoot, err := bc.TxMerkleRoot([]*bc.Tx{genesisCoinbaseTx.Tx})
-       if err != nil {
-               log.Panicf("Fatal create tx merkelRoot")
-       }
-
+// GenesisBlock will return genesis block
+func GenesisBlock() *types.Block {
+       tx := genesisTx()
        txStatus := bc.NewTransactionStatus()
        txStatus.SetStatus(0, false)
        txStatusHash, err := bc.TxStatusMerkleRoot(txStatus.VerifyStatus)
        if err != nil {
-               log.Panicf("Fatal create tx status gmerkelRoot")
+               log.Panicf("fail on calc genesis tx status merkle root")
+       }
+
+       merkleRoot, err := bc.TxMerkleRoot([]*bc.Tx{tx.Tx})
+       if err != nil {
+               log.Panicf("fail on calc genesis tx merkel root")
        }
 
        block := &types.Block{
                BlockHeader: types.BlockHeader{
                        Version:   1,
                        Height:    0,
-                       Nonce:     4216236,
+                       Nonce:     2083236893,
                        Timestamp: 1524202000,
+                       Bits:      2089670227111054243,
                        BlockCommitment: types.BlockCommitment{
                                TransactionsMerkleRoot: merkleRoot,
                                TransactionStatusHash:  txStatusHash,
                        },
-                       Bits: 2089670227111054243,
                },
-               Transactions: []*types.Tx{genesisCoinbaseTx},
+               Transactions: []*types.Tx{tx},
        }
        return block
 }
index 4acab69..3c30938 100644 (file)
@@ -1,16 +1,5 @@
 package config
 
-import (
-       "testing"
-)
-
-// test genesis
-func TestGenerateGenesisTx(t *testing.T) {
-       if tx := GenerateGenesisTx(); tx == nil {
-               t.Errorf("Generate genesis tx failed")
-       }
-}
-
 /*func TestGenerateGenesisBlock(t *testing.T) {
        block := GenerateGenesisBlock()
        nonce := block.Nonce
index b6ed2fa..2f2af76 100644 (file)
@@ -19,7 +19,7 @@ const (
        CoinbasePendingBlockNumber = uint64(100)
        subsidyReductionInterval   = uint64(840000)
        baseSubsidy                = uint64(41250000000)
-       InitialBlockSubsidy        = uint64(1470000041250000000)
+       InitialBlockSubsidy        = uint64(147000041250000000)
 
        // config for pow mining
        PowMinBits            = uint64(2305843009213861724)
index 97e2e7b..74fbc9d 100644 (file)
@@ -15,7 +15,7 @@ func TestLoadBlockIndex(t *testing.T) {
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
        store := NewStore(testDB)
 
-       block := config.GenerateGenesisBlock()
+       block := config.GenesisBlock()
        txStatus := bc.NewTransactionStatus()
 
        if err := store.SaveBlock(block, txStatus); err != nil {
index e321e93..58a27bd 100644 (file)
@@ -10,7 +10,7 @@ import (
 
 func TestCalcReorganizeNodes(t *testing.T) {
        c := &Chain{index: state.NewBlockIndex()}
-       header := config.GenerateGenesisBlock().BlockHeader
+       header := config.GenesisBlock().BlockHeader
        initNode, err := state.NewBlockNode(&header, nil)
        if err != nil {
                t.Fatal(err)
index b3763ce..015cb94 100644 (file)
@@ -60,7 +60,7 @@ func NewChain(store Store, txPool *TxPool) (*Chain, error) {
 }
 
 func (c *Chain) initChainStatus() error {
-       genesisBlock := config.GenerateGenesisBlock()
+       genesisBlock := config.GenesisBlock()
        txStatus := bc.NewTransactionStatus()
        for i := range genesisBlock.Transactions {
                txStatus.SetStatus(i, false)
index 7aafa1f..b80cf1b 100644 (file)
@@ -174,9 +174,9 @@ func (w *Wallet) RescanBlocks() {
 func (w *Wallet) getRescanNotification() {
        select {
        case <-w.rescanCh:
-               w.status.WorkHeight = 0
-               block, _ := w.chain.GetBlockByHeight(w.status.WorkHeight)
-               w.status.WorkHash = block.Hash()
+               block, _ := w.chain.GetBlockByHeight(0)
+               w.status.WorkHash = bc.Hash{}
+               w.AttachBlock(block)
        default:
                return
        }