X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=config%2Fgenesis.go;h=a3b2f7e2a91ccaf1099f626dadb2e423403e60b2;hb=3a6cd9640bdb0eed33451a5af7a0e12cfe423165;hp=1443862f3726a70c2a77f8d90249fc69af8d4e32;hpb=cc968002ceac2dfd7665c2ac2b4c32ab6017b525;p=bytom%2Fvapor.git diff --git a/config/genesis.go b/config/genesis.go index 1443862f..a3b2f7e2 100644 --- a/config/genesis.go +++ b/config/genesis.go @@ -1,67 +1,71 @@ package config import ( - "bytes" - "crypto/sha256" "encoding/hex" log "github.com/sirupsen/logrus" "github.com/vapor/consensus" - "github.com/vapor/crypto/ed25519" + "github.com/vapor/crypto" "github.com/vapor/crypto/ed25519/chainkd" "github.com/vapor/protocol/bc" "github.com/vapor/protocol/bc/types" "github.com/vapor/protocol/vm/vmutil" ) -func commitToArguments() (res *[32]byte) { - var fedpegPubkeys []ed25519.PublicKey - for _, xpub := range consensus.ActiveNetParams.FedpegXPubs { - fedpegPubkeys = append(fedpegPubkeys, xpub.PublicKey()) - } - fedpegScript, _ := vmutil.P2SPMultiSigProgram(fedpegPubkeys, len(fedpegPubkeys)) +// FedAddressPath is used to derive federation root xpubs for signing cross-chain txs +var FedAddressPath = [][]byte{ + []byte{0x2C, 0x00, 0x00, 0x00}, + []byte{0x99, 0x00, 0x00, 0x00}, + []byte{0x01, 0x00, 0x00, 0x00}, + []byte{0x00, 0x00, 0x00, 0x00}, + []byte{0x01, 0x00, 0x00, 0x00}, +} - var buffer bytes.Buffer - for _, address := range CommonConfig.Consensus.Dpos.Signers { - redeemContract := address.ScriptAddress() - buffer.Write(redeemContract) +func FederationPMultiSigScript(c *Config) []byte { + xpubs := c.Federation.Xpubs + derivedXPubs := chainkd.DeriveXPubs(xpubs, FedAddressPath) + program, err := vmutil.P2SPMultiSigProgram(chainkd.XPubKeys(derivedXPubs), c.Federation.Quorum) + if err != nil { + log.Panicf("fail to generate federation scirpt for federation: %v", err) } - hasher := sha256.New() - hasher.Write(fedpegScript) - hasher.Write(buffer.Bytes()) - resSlice := hasher.Sum(nil) - res = new([32]byte) - copy(res[:], resSlice) - return + return program } -func genesisTx() *types.Tx { +func FederationWScript(c *Config) []byte { + script := FederationPMultiSigScript(c) + scriptHash := crypto.Sha256(script) + wscript, err := vmutil.P2WSHProgram(scriptHash) + if err != nil { + log.Panicf("Fail converts scriptHash to witness: %v", err) + } + + return wscript +} +func GenesisTx() *types.Tx { contract, err := hex.DecodeString("00148c9d063ff74ee6d9ffa88d83aeb038068366c4c4") if err != nil { log.Panicf("fail on decode genesis tx output control program") } - coinbaseInput := commitToArguments() + coinbaseInput := FederationWScript(CommonConfig) + txData := types.TxData{ Version: 1, Inputs: []*types.TxInput{ - // Any consensus-related values that are command-line set can be added here for anti-footgun types.NewCoinbaseInput(coinbaseInput[:]), - //types.NewCoinbaseInput([]byte("Information is power. -- Jan/11/2013. Computing is power. -- Apr/24/2018.")), }, Outputs: []*types.TxOutput{ - types.NewTxOutput(*consensus.BTMAssetID, consensus.InitialBlockSubsidy, contract), + types.NewIntraChainOutput(*consensus.BTMAssetID, consensus.BlockSubsidy(0), contract), }, } - return types.NewTx(txData) } func mainNetGenesisBlock() *types.Block { - tx := genesisTx() + tx := GenesisTx() txStatus := bc.NewTransactionStatus() if err := txStatus.SetStatus(0, false); err != nil { log.Panicf(err.Error()) @@ -76,23 +80,15 @@ func mainNetGenesisBlock() *types.Block { log.Panicf("fail on calc genesis tx merkel root") } - var xPrv chainkd.XPrv - if CommonConfig.Consensus.Dpos.XPrv == "" { - log.Panicf("Signer is empty") - } - xPrv.UnmarshalText([]byte(CommonConfig.Consensus.Dpos.XPrv)) - b, _ := xPrv.XPub().MarshalText() - block := &types.Block{ BlockHeader: types.BlockHeader{ Version: 1, Height: 0, - Timestamp: 1524549600, + Timestamp: 1563344560002, BlockCommitment: types.BlockCommitment{ TransactionsMerkleRoot: merkleRoot, TransactionStatusHash: txStatusHash, }, - Coinbase: b, }, Transactions: []*types.Tx{tx}, } @@ -100,7 +96,7 @@ func mainNetGenesisBlock() *types.Block { } func testNetGenesisBlock() *types.Block { - tx := genesisTx() + tx := GenesisTx() txStatus := bc.NewTransactionStatus() if err := txStatus.SetStatus(0, false); err != nil { log.Panicf(err.Error()) @@ -115,23 +111,15 @@ func testNetGenesisBlock() *types.Block { log.Panicf("fail on calc genesis tx merkel root") } - var xPrv chainkd.XPrv - if CommonConfig.Consensus.Dpos.XPrv == "" { - log.Panicf("Signer is empty") - } - xPrv.UnmarshalText([]byte(CommonConfig.Consensus.Dpos.XPrv)) - b, _ := xPrv.XPub().MarshalText() - block := &types.Block{ BlockHeader: types.BlockHeader{ Version: 1, Height: 0, - Timestamp: 1528945000, + Timestamp: 1563344560001, BlockCommitment: types.BlockCommitment{ TransactionsMerkleRoot: merkleRoot, TransactionStatusHash: txStatusHash, }, - Coinbase: b, }, Transactions: []*types.Tx{tx}, } @@ -139,7 +127,7 @@ func testNetGenesisBlock() *types.Block { } func soloNetGenesisBlock() *types.Block { - tx := genesisTx() + tx := GenesisTx() txStatus := bc.NewTransactionStatus() if err := txStatus.SetStatus(0, false); err != nil { log.Panicf(err.Error()) @@ -154,23 +142,15 @@ func soloNetGenesisBlock() *types.Block { log.Panicf("fail on calc genesis tx merkel root") } - var xPrv chainkd.XPrv - if CommonConfig.Consensus.Dpos.XPrv == "" { - log.Panicf("Signer is empty") - } - xPrv.UnmarshalText([]byte(CommonConfig.Consensus.Dpos.XPrv)) - b, _ := xPrv.XPub().MarshalText() - block := &types.Block{ BlockHeader: types.BlockHeader{ Version: 1, Height: 0, - Timestamp: 1528945000, + Timestamp: 1563344560000, BlockCommitment: types.BlockCommitment{ TransactionsMerkleRoot: merkleRoot, TransactionStatusHash: txStatusHash, }, - Coinbase: b, }, Transactions: []*types.Tx{tx}, }