OSDN Git Service

init version of edit block header (#389)
authorPaladz <yzhu101@uottawa.ca>
Thu, 1 Mar 2018 09:51:01 +0000 (17:51 +0800)
committerGitHub <noreply@github.com>
Thu, 1 Mar 2018 09:51:01 +0000 (17:51 +0800)
* init version of edit block header

* elegant the code a little bit

* fix isssue error

20 files changed:
blockchain/asset/builder.go
blockchain/txdb/store.go
blockchain/wallet/annotated.go
blockchain/wallet/indexer.go
blockchain/wallet/wallet.go
blockchain/wallet/wallet_test.go
config/genesis.go
mining/mining.go
protocol/bc/bc.pb.go
protocol/bc/bc.proto
protocol/bc/blockheader.go
protocol/bc/legacy/block_commitment.go
protocol/bc/legacy/block_header.go
protocol/bc/legacy/block_test.go
protocol/bc/legacy/map.go
protocol/bc/tx_status.go
protocol/block.go
protocol/protocol.go
protocol/validation/validation.go
protocol/validation/validation_test.go

index 1511c07..3e6eb84 100755 (executable)
@@ -59,7 +59,7 @@ func (a *issueAction) Build(ctx context.Context, builder *txbuilder.TemplateBuil
 
        tplIn := &txbuilder.SigningInstruction{}
        path := signers.Path(asset.Signer, signers.AssetKeySpace)
-       tplIn.AddWitnessKeys(asset.Signer.XPubs, path, asset.Signer.Quorum)
+       tplIn.AddRawWitnessKeys(asset.Signer.XPubs, path, asset.Signer.Quorum)
 
        log.Info("Issue action build")
        builder.RestrictMinTime(time.Now())
index 60618c6..e5442da 100644 (file)
@@ -4,16 +4,21 @@ import (
        "encoding/json"
        "fmt"
 
+       "github.com/golang/protobuf/proto"
        "github.com/tendermint/tmlibs/common"
        dbm "github.com/tendermint/tmlibs/db"
 
        "github.com/bytom/blockchain/txdb/storage"
+       "github.com/bytom/errors"
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/legacy"
        "github.com/bytom/protocol/state"
 )
 
-var blockStoreKey = []byte("blockStore")
+var (
+       blockStoreKey  = []byte("blockStore")
+       txStatusPrefix = []byte("txStatus:")
+)
 
 // BlockStoreStateJSON represents the core's db status
 type BlockStoreStateJSON struct {
@@ -55,6 +60,10 @@ func calcBlockKey(hash *bc.Hash) []byte {
        return []byte(fmt.Sprintf("B:%v", hash.String()))
 }
 
+func calcTxStatusKey(hash *bc.Hash) []byte {
+       return append(txStatusPrefix, hash.Bytes()...)
+}
+
 // GetBlock return the block by given hash
 func GetBlock(db dbm.DB, hash *bc.Hash) *legacy.Block {
        bytez := db.Get(calcBlockKey(hash))
@@ -99,6 +108,20 @@ func (s *Store) GetTransactionsUtxo(view *state.UtxoViewpoint, txs []*bc.Tx) err
        return getTransactionsUtxo(s.db, view, txs)
 }
 
+// GetTransactionStatus will return the utxo that related to the block hash
+func (s *Store) GetTransactionStatus(hash *bc.Hash) (*bc.TransactionStatus, error) {
+       data := s.db.Get(calcTxStatusKey(hash))
+       if data == nil {
+               return nil, errors.New("can't find the transaction status by given hash")
+       }
+
+       ts := &bc.TransactionStatus{}
+       if err := proto.Unmarshal(data, ts); err != nil {
+               return nil, errors.Wrap(err, "unmarshaling transaction status")
+       }
+       return ts, nil
+}
+
 // GetStoreStatus return the BlockStoreStateJSON
 func (s *Store) GetStoreStatus() BlockStoreStateJSON {
        return loadBlockStoreStateJSON(s.db)
@@ -110,15 +133,22 @@ func (s *Store) GetMainchain(hash *bc.Hash) (map[uint64]*bc.Hash, error) {
 }
 
 // SaveBlock persists a new block in the database.
-func (s *Store) SaveBlock(block *legacy.Block) error {
+func (s *Store) SaveBlock(block *legacy.Block, ts *bc.TransactionStatus) error {
        binaryBlock, err := block.MarshalText()
        if err != nil {
-               common.PanicCrisis(common.Fmt("Error Marshal block meta: %v", err))
+               return errors.Wrap(err, "Marshal block meta")
+       }
+
+       binaryTxStatus, err := proto.Marshal(ts)
+       if err != nil {
+               return errors.Wrap(err, "marshal block transaction status")
        }
 
        blockHash := block.Hash()
-       s.db.Set(calcBlockKey(&blockHash), binaryBlock)
-       s.db.SetSync(nil, nil)
+       batch := s.db.NewBatch()
+       batch.Set(calcBlockKey(&blockHash), binaryBlock)
+       batch.Set(calcTxStatusKey(&blockHash), binaryTxStatus)
+       batch.Write()
        return nil
 }
 
index 8f5f057..e29610b 100755 (executable)
@@ -172,8 +172,7 @@ func isValidJSON(b []byte) bool {
        return err == nil
 }
 
-func buildAnnotatedTransaction(orig *legacy.Tx, b *legacy.Block, indexInBlock int) *query.AnnotatedTx {
-       statusFail, _ := b.TransactionStatus.GetStatus(indexInBlock)
+func buildAnnotatedTransaction(orig *legacy.Tx, b *legacy.Block, statusFail bool, indexInBlock int) *query.AnnotatedTx {
        tx := &query.AnnotatedTx{
                ID:                     orig.ID,
                Timestamp:              b.Time(),
index 815be77..c8c21c1 100755 (executable)
@@ -80,7 +80,7 @@ func (w *Wallet) deleteTransactions(batch db.Batch, height uint64) {
 }
 
 //ReverseAccountUTXOs process the invalid blocks when orphan block rollback
-func (w *Wallet) reverseAccountUTXOs(batch db.Batch, b *legacy.Block) {
+func (w *Wallet) reverseAccountUTXOs(batch db.Batch, b *legacy.Block, txStatus *bc.TransactionStatus) {
        var err error
 
        //unknow how many spent and retire outputs
@@ -100,7 +100,7 @@ func (w *Wallet) reverseAccountUTXOs(batch db.Batch, b *legacy.Block) {
                                continue
                        }
 
-                       statusFail, _ := b.TransactionStatus.GetStatus(txIndex)
+                       statusFail, _ := txStatus.GetStatus(txIndex)
                        if statusFail && *resOut.Source.Value.AssetId != *consensus.BTMAssetID {
                                continue
                        }
@@ -160,6 +160,7 @@ func saveExternalAssetDefinition(b *legacy.Block, walletDB db.DB) {
        }
 }
 
+// Summary is ....
 type Summary struct {
        Type         string             `json:"type"`
        AssetID      bc.AssetID         `json:"asset_id,omitempty"`
@@ -170,6 +171,7 @@ type Summary struct {
        Arbitrary    chainjson.HexBytes `json:"arbitrary,omitempty"`
 }
 
+// TxSummary is ....
 type TxSummary struct {
        ID        bc.Hash   `json:"id"`
        Timestamp time.Time `json:"timestamp"`
@@ -178,8 +180,8 @@ type TxSummary struct {
 }
 
 //indexTransactions saves all annotated transactions to the database.
-func (w *Wallet) indexTransactions(batch db.Batch, b *legacy.Block) error {
-       annotatedTxs := filterAccountTxs(b, w)
+func (w *Wallet) indexTransactions(batch db.Batch, b *legacy.Block, txStatus *bc.TransactionStatus) error {
+       annotatedTxs := w.filterAccountTxs(b, txStatus)
        saveExternalAssetDefinition(b, w.DB)
        annotateTxsAsset(w, annotatedTxs)
        annotateTxsAccount(annotatedTxs, w.DB)
@@ -198,11 +200,9 @@ func (w *Wallet) indexTransactions(batch db.Batch, b *legacy.Block) error {
 }
 
 //buildAccountUTXOs process valid blocks to build account unspent outputs db
-func (w *Wallet) buildAccountUTXOs(batch db.Batch, b *legacy.Block) {
-       var err error
-
+func (w *Wallet) buildAccountUTXOs(batch db.Batch, b *legacy.Block, txStatus *bc.TransactionStatus) {
        //handle spent UTXOs
-       delOutputIDs := prevoutDBKeys(b)
+       delOutputIDs := prevoutDBKeys(b, txStatus)
        for _, delOutputID := range delOutputIDs {
                batch.Delete(account.UTXOKey(delOutputID))
        }
@@ -216,7 +216,7 @@ func (w *Wallet) buildAccountUTXOs(batch db.Batch, b *legacy.Block) {
                        if !ok {
                                continue
                        }
-                       statusFail, _ := b.TransactionStatus.GetStatus(txIndex)
+                       statusFail, _ := txStatus.GetStatus(txIndex)
                        if statusFail && *resOut.Source.Value.AssetId != *consensus.BTMAssetID {
                                continue
                        }
@@ -240,17 +240,17 @@ func (w *Wallet) buildAccountUTXOs(batch db.Batch, b *legacy.Block) {
        }
        accOuts := loadAccountInfo(outs, w)
 
-       if err = upsertConfirmedAccountOutputs(accOuts, batch); err != nil {
+       if err := upsertConfirmedAccountOutputs(accOuts, batch); err != nil {
                log.WithField("err", err).Error("building new account outputs")
                return
        }
 }
 
-func prevoutDBKeys(b *legacy.Block) (outputIDs []bc.Hash) {
+func prevoutDBKeys(b *legacy.Block, txStatus *bc.TransactionStatus) (outputIDs []bc.Hash) {
        for txIndex, tx := range b.Transactions {
                for _, inpID := range tx.Tx.InputIDs {
                        if sp, err := tx.Spend(inpID); err == nil {
-                               statusFail, _ := b.TransactionStatus.GetStatus(txIndex)
+                               statusFail, _ := txStatus.GetStatus(txIndex)
                                if statusFail && *sp.WitnessDestination.Value.AssetId != *consensus.BTMAssetID {
                                        continue
                                }
@@ -338,16 +338,17 @@ func upsertConfirmedAccountOutputs(outs []*accountOutput, batch db.Batch) error
 }
 
 // filt related and build the fully annotated transactions.
-func filterAccountTxs(b *legacy.Block, w *Wallet) []*query.AnnotatedTx {
+func (w *Wallet) filterAccountTxs(b *legacy.Block, txStatus *bc.TransactionStatus) []*query.AnnotatedTx {
        annotatedTxs := make([]*query.AnnotatedTx, 0, len(b.Transactions))
        for pos, tx := range b.Transactions {
+               statusFail, _ := txStatus.GetStatus(pos)
                local := false
                for _, v := range tx.Outputs {
                        var hash [32]byte
 
                        sha3pool.Sum256(hash[:], v.ControlProgram)
                        if bytes := w.DB.Get(account.CPKey(hash)); bytes != nil {
-                               annotatedTxs = append(annotatedTxs, buildAnnotatedTransaction(tx, b, pos))
+                               annotatedTxs = append(annotatedTxs, buildAnnotatedTransaction(tx, b, statusFail, pos))
                                local = true
                                break
                        }
@@ -363,7 +364,7 @@ func filterAccountTxs(b *legacy.Block, w *Wallet) []*query.AnnotatedTx {
                                continue
                        }
                        if bytes := w.DB.Get(account.UTXOKey(outid)); bytes != nil {
-                               annotatedTxs = append(annotatedTxs, buildAnnotatedTransaction(tx, b, pos))
+                               annotatedTxs = append(annotatedTxs, buildAnnotatedTransaction(tx, b, statusFail, pos))
                                break
                        }
                }
index 057c2b4..9d8e3b6 100755 (executable)
@@ -148,9 +148,15 @@ func (w *Wallet) attachBlock(block *legacy.Block) error {
                return nil
        }
 
+       blockHash := block.Hash()
+       txStatus, err := w.chain.GetTransactionStatus(&blockHash)
+       if err != nil {
+               return err
+       }
+
        storeBatch := w.DB.NewBatch()
-       w.indexTransactions(storeBatch, block)
-       w.buildAccountUTXOs(storeBatch, block)
+       w.indexTransactions(storeBatch, block, txStatus)
+       w.buildAccountUTXOs(storeBatch, block, txStatus)
 
        w.status.WorkHeight = block.Height
        w.status.WorkHash = block.Hash()
@@ -162,8 +168,14 @@ func (w *Wallet) attachBlock(block *legacy.Block) error {
 }
 
 func (w *Wallet) detachBlock(block *legacy.Block) error {
+       blockHash := block.Hash()
+       txStatus, err := w.chain.GetTransactionStatus(&blockHash)
+       if err != nil {
+               return err
+       }
+
        storeBatch := w.DB.NewBatch()
-       w.reverseAccountUTXOs(storeBatch, block)
+       w.reverseAccountUTXOs(storeBatch, block, txStatus)
        w.deleteTransactions(storeBatch, w.status.BestHeight)
 
        w.status.BestHeight = block.Height - 1
index 1c13631..9d430c1 100755 (executable)
@@ -79,6 +79,9 @@ func TestWalletUpdate(t *testing.T) {
 
        block := mockSingleBlock(tx)
 
+       txStatus := bc.NewTransactionStatus()
+       store.SaveBlock(block, txStatus)
+
        err = w.attachBlock(block)
        if err != nil {
                t.Fatal(err)
index 49714e4..c260bf5 100644 (file)
@@ -41,6 +41,7 @@ func GenerateGenesisBlock() *legacy.Block {
        if err != nil {
                log.Panicf("Fatal create merkelRoot")
        }
+       txStatus := bc.NewTransactionStatus()
 
        block := &legacy.Block{
                BlockHeader: legacy.BlockHeader{
@@ -50,11 +51,9 @@ func GenerateGenesisBlock() *legacy.Block {
                        Timestamp: 1516788453,
                        BlockCommitment: legacy.BlockCommitment{
                                TransactionsMerkleRoot: merkleRoot,
+                               TransactionStatusHash:  bc.EntryID(txStatus),
                        },
                        Bits: 2305843009222082559,
-                       TransactionStatus: bc.TransactionStatus{
-                               Bitmap: []byte{0},
-                       },
                },
                Transactions: []*legacy.Tx{genesisCoinbaseTx},
        }
index 114c695..8ef0fba 100644 (file)
@@ -61,6 +61,7 @@ func createCoinbaseTx(accountManager *account.Manager, amount uint64, blockHeigh
 // NewBlockTemplate returns a new block template that is ready to be solved
 func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager *account.Manager) (b *legacy.Block, err error) {
        view := state.NewUtxoViewpoint()
+       txStatus := bc.NewTransactionStatus()
        txEntries := []*bc.Tx{nil}
        blockWeight := uint64(0)
        txFee := uint64(0)
@@ -81,7 +82,6 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
                        Height:            nextBlockHeight,
                        PreviousBlockHash: preBlock.Hash(),
                        Timestamp:         uint64(time.Now().Unix()),
-                       TransactionStatus: *bc.NewTransactionStatus(),
                        BlockCommitment:   legacy.BlockCommitment{},
                        Bits:              difficulty.CalcNextRequiredDifficulty(&preBlock.BlockHeader, compareDiffBH),
                },
@@ -119,7 +119,7 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
                        continue
                }
 
-               b.BlockHeader.TransactionStatus.SetStatus(len(b.Transactions), gasOnlyTx)
+               txStatus.SetStatus(len(b.Transactions), gasOnlyTx)
                b.Transactions = append(b.Transactions, txDesc.Tx)
                txEntries = append(txEntries, tx)
                blockWeight += txDesc.Weight
@@ -134,5 +134,6 @@ func NewBlockTemplate(c *protocol.Chain, txPool *protocol.TxPool, accountManager
        txEntries[0] = b.Transactions[0].Tx
 
        b.BlockHeader.BlockCommitment.TransactionsMerkleRoot, err = bc.MerkleRoot(txEntries)
+       b.BlockHeader.BlockCommitment.TransactionStatusHash = bc.EntryID(txStatus)
        return b, err
 }
index 100517f..e8dff58 100644 (file)
@@ -273,17 +273,16 @@ func (m *ValueDestination) GetPosition() uint64 {
 }
 
 type BlockHeader struct {
-       Version           uint64             `protobuf:"varint,1,opt,name=version" json:"version,omitempty"`
-       SerializedSize    uint64             `protobuf:"varint,2,opt,name=serialized_size,json=serializedSize" json:"serialized_size,omitempty"`
-       Height            uint64             `protobuf:"varint,3,opt,name=height" json:"height,omitempty"`
-       PreviousBlockId   *Hash              `protobuf:"bytes,4,opt,name=previous_block_id,json=previousBlockId" json:"previous_block_id,omitempty"`
-       Seed              *Hash              `protobuf:"bytes,5,opt,name=seed" json:"seed,omitempty"`
-       Timestamp         uint64             `protobuf:"varint,6,opt,name=timestamp" json:"timestamp,omitempty"`
-       TransactionsRoot  *Hash              `protobuf:"bytes,7,opt,name=transactions_root,json=transactionsRoot" json:"transactions_root,omitempty"`
-       AssetsRoot        *Hash              `protobuf:"bytes,8,opt,name=assets_root,json=assetsRoot" json:"assets_root,omitempty"`
-       TransactionStatus *TransactionStatus `protobuf:"bytes,9,opt,name=transaction_status,json=transactionStatus" json:"transaction_status,omitempty"`
-       Nonce             uint64             `protobuf:"varint,10,opt,name=nonce" json:"nonce,omitempty"`
-       Bits              uint64             `protobuf:"varint,11,opt,name=bits" json:"bits,omitempty"`
+       Version               uint64             `protobuf:"varint,1,opt,name=version" json:"version,omitempty"`
+       SerializedSize        uint64             `protobuf:"varint,2,opt,name=serialized_size,json=serializedSize" json:"serialized_size,omitempty"`
+       Height                uint64             `protobuf:"varint,3,opt,name=height" json:"height,omitempty"`
+       PreviousBlockId       *Hash              `protobuf:"bytes,4,opt,name=previous_block_id,json=previousBlockId" json:"previous_block_id,omitempty"`
+       Timestamp             uint64             `protobuf:"varint,5,opt,name=timestamp" json:"timestamp,omitempty"`
+       TransactionsRoot      *Hash              `protobuf:"bytes,6,opt,name=transactions_root,json=transactionsRoot" json:"transactions_root,omitempty"`
+       TransactionStatusHash *Hash              `protobuf:"bytes,7,opt,name=transaction_status_hash,json=transactionStatusHash" json:"transaction_status_hash,omitempty"`
+       Nonce                 uint64             `protobuf:"varint,8,opt,name=nonce" json:"nonce,omitempty"`
+       Bits                  uint64             `protobuf:"varint,9,opt,name=bits" json:"bits,omitempty"`
+       TransactionStatus     *TransactionStatus `protobuf:"bytes,10,opt,name=transaction_status,json=transactionStatus" json:"transaction_status,omitempty"`
 }
 
 func (m *BlockHeader) Reset()                    { *m = BlockHeader{} }
@@ -319,13 +318,6 @@ func (m *BlockHeader) GetPreviousBlockId() *Hash {
        return nil
 }
 
-func (m *BlockHeader) GetSeed() *Hash {
-       if m != nil {
-               return m.Seed
-       }
-       return nil
-}
-
 func (m *BlockHeader) GetTimestamp() uint64 {
        if m != nil {
                return m.Timestamp
@@ -340,16 +332,9 @@ func (m *BlockHeader) GetTransactionsRoot() *Hash {
        return nil
 }
 
-func (m *BlockHeader) GetAssetsRoot() *Hash {
+func (m *BlockHeader) GetTransactionStatusHash() *Hash {
        if m != nil {
-               return m.AssetsRoot
-       }
-       return nil
-}
-
-func (m *BlockHeader) GetTransactionStatus() *TransactionStatus {
-       if m != nil {
-               return m.TransactionStatus
+               return m.TransactionStatusHash
        }
        return nil
 }
@@ -368,6 +353,13 @@ func (m *BlockHeader) GetBits() uint64 {
        return 0
 }
 
+func (m *BlockHeader) GetTransactionStatus() *TransactionStatus {
+       if m != nil {
+               return m.TransactionStatus
+       }
+       return nil
+}
+
 type TxHeader struct {
        Version        uint64  `protobuf:"varint,1,opt,name=version" json:"version,omitempty"`
        SerializedSize uint64  `protobuf:"varint,2,opt,name=serialized_size,json=serializedSize" json:"serialized_size,omitempty"`
@@ -807,68 +799,67 @@ func init() {
 func init() { proto.RegisterFile("bc.proto", fileDescriptor0) }
 
 var fileDescriptor0 = []byte{
-       // 994 bytes of a gzipped FileDescriptorProto
+       // 984 bytes of a gzipped FileDescriptorProto
        0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcd, 0x6e, 0xdb, 0x46,
-       0x10, 0x06, 0x45, 0x4a, 0xa4, 0x46, 0xae, 0x65, 0xaf, 0xdd, 0x80, 0x08, 0x1c, 0xc0, 0x60, 0xe1,
-       0x3a, 0x41, 0x00, 0xc3, 0xb1, 0xd3, 0xa2, 0x87, 0x5e, 0xdc, 0xba, 0x6d, 0x74, 0x70, 0x5b, 0xd0,
-       0x41, 0xae, 0xc4, 0x8a, 0xdc, 0x58, 0x8b, 0x4a, 0x5c, 0x75, 0x77, 0xa9, 0xba, 0x7e, 0x8c, 0x5e,
-       0xfb, 0x0a, 0x3d, 0xf5, 0xd8, 0x73, 0x1e, 0xa2, 0xcf, 0xd1, 0x27, 0x28, 0x76, 0xb8, 0x94, 0x28,
-       0x59, 0x4a, 0x24, 0x24, 0xb9, 0x71, 0x7e, 0x76, 0x7e, 0xbe, 0x99, 0x8f, 0xbb, 0x10, 0xf4, 0xd3,
-       0x93, 0xb1, 0x14, 0x5a, 0x90, 0x46, 0x3f, 0x8d, 0xbe, 0x07, 0xef, 0x05, 0x55, 0x03, 0xb2, 0x0d,
-       0x8d, 0xc9, 0x69, 0xe8, 0x1c, 0x3a, 0x8f, 0x5b, 0x71, 0x63, 0x72, 0x8a, 0xf2, 0xb3, 0xb0, 0x61,
-       0xe5, 0x67, 0x28, 0x9f, 0x85, 0xae, 0x95, 0xcf, 0x50, 0x3e, 0x0f, 0x3d, 0x2b, 0x9f, 0x47, 0x5f,
-       0x83, 0xff, 0xb3, 0x14, 0x37, 0x92, 0x8e, 0xc8, 0x23, 0x80, 0xc9, 0x28, 0x99, 0x30, 0xa9, 0xb8,
-       0xc8, 0x31, 0xa4, 0x17, 0xb7, 0x27, 0xa3, 0x57, 0xa5, 0x82, 0x10, 0xf0, 0x52, 0x91, 0x31, 0x8c,
-       0xbd, 0x15, 0xe3, 0x77, 0xd4, 0x03, 0xff, 0x42, 0x29, 0xa6, 0x7b, 0x97, 0xef, 0x5d, 0xc8, 0x15,
-       0x74, 0x30, 0xd4, 0xc5, 0x48, 0x14, 0xb9, 0x26, 0x9f, 0x43, 0x40, 0x8d, 0x98, 0xf0, 0x0c, 0x83,
-       0x76, 0xce, 0x3a, 0x27, 0xfd, 0xf4, 0xc4, 0x66, 0x8b, 0x7d, 0x34, 0xf6, 0x32, 0xf2, 0x00, 0x5a,
-       0x14, 0x4f, 0x60, 0x2a, 0x2f, 0xb6, 0x52, 0xf4, 0xa7, 0x03, 0x5d, 0x74, 0xbe, 0x64, 0xaf, 0x79,
-       0xce, 0xb5, 0xe9, 0xe0, 0x0c, 0x76, 0xf0, 0x93, 0x0e, 0x93, 0xfe, 0x50, 0xa4, 0xbf, 0xcc, 0x62,
-       0x07, 0x26, 0xb6, 0xc1, 0x33, 0xde, 0xb6, 0x1e, 0xdf, 0x18, 0x87, 0x5e, 0x46, 0xbe, 0x84, 0x1d,
-       0xae, 0x54, 0x41, 0xf3, 0x94, 0x25, 0xe3, 0x12, 0x28, 0xcc, 0x64, 0xeb, 0xb1, 0xd8, 0xc5, 0xdd,
-       0xca, 0xa9, 0x02, 0xf3, 0x00, 0xbc, 0x8c, 0x6a, 0x8a, 0x0d, 0xd7, 0xe3, 0xa3, 0x36, 0x1a, 0x42,
-       0xe7, 0x15, 0x1d, 0x16, 0xec, 0x5a, 0x14, 0x32, 0x65, 0xe4, 0x21, 0xb8, 0x92, 0xbd, 0xbe, 0x57,
-       0x8b, 0x51, 0x92, 0x23, 0x68, 0x4e, 0x8c, 0xab, 0xcd, 0xda, 0x9d, 0xa2, 0x50, 0x02, 0x15, 0x97,
-       0x56, 0xf2, 0x10, 0x82, 0xb1, 0x50, 0xd8, 0x27, 0xe6, 0xf4, 0xe2, 0xa9, 0x1c, 0xfd, 0x0a, 0x3b,
-       0x98, 0xed, 0x92, 0x29, 0xcd, 0x73, 0x8a, 0x58, 0x7c, 0xe4, 0x94, 0x7f, 0xb9, 0xd0, 0x41, 0x08,
-       0x5f, 0x30, 0x9a, 0x31, 0x49, 0x42, 0xf0, 0xe7, 0x17, 0xab, 0x12, 0xc9, 0x31, 0x74, 0x15, 0x93,
-       0x9c, 0x0e, 0xf9, 0x1d, 0xcb, 0x12, 0xc5, 0xef, 0x98, 0x9d, 0xe4, 0xf6, 0x4c, 0x7d, 0xcd, 0xef,
-       0x98, 0x99, 0xf4, 0x80, 0xf1, 0x9b, 0x81, 0xb6, 0xc9, 0xac, 0x44, 0x9e, 0xc3, 0xee, 0x58, 0xb2,
-       0x09, 0x17, 0x85, 0x9a, 0x8d, 0xd5, 0x5b, 0xe8, 0xab, 0x5b, 0xb9, 0x54, 0x73, 0x3d, 0x00, 0x4f,
-       0x31, 0x96, 0x85, 0xcd, 0xc5, 0xf9, 0x18, 0x2d, 0x39, 0x80, 0xb6, 0xe6, 0x23, 0xa6, 0x34, 0x1d,
-       0x8d, 0xc3, 0x56, 0xc9, 0x84, 0xa9, 0x82, 0x7c, 0x01, 0xbb, 0x5a, 0xd2, 0x5c, 0xd1, 0xd4, 0xf4,
-       0xaa, 0x12, 0x29, 0x84, 0x0e, 0xfd, 0x85, 0x40, 0x3b, 0x75, 0x97, 0x58, 0x08, 0x4d, 0x9e, 0x40,
-       0x07, 0xb7, 0xd6, 0x1e, 0x08, 0x16, 0x0e, 0x40, 0x69, 0x44, 0xd7, 0x4b, 0x20, 0xb5, 0xe3, 0x89,
-       0xd2, 0x54, 0x17, 0x2a, 0x6c, 0xe3, 0x89, 0x4f, 0xcd, 0x89, 0x97, 0x33, 0xeb, 0x35, 0x1a, 0xe3,
-       0x7a, 0x49, 0xa5, 0x8a, 0xec, 0x43, 0x33, 0x17, 0x79, 0xca, 0x42, 0xc0, 0x0e, 0x4a, 0xc1, 0xf0,
-       0xb8, 0xcf, 0xb5, 0x0a, 0x3b, 0xa8, 0xc4, 0xef, 0xe8, 0x5f, 0x07, 0x82, 0x97, 0xb7, 0x1f, 0x6e,
-       0x56, 0x8f, 0x00, 0x0c, 0x5c, 0x89, 0xa4, 0xf9, 0x0d, 0xb3, 0xf3, 0x42, 0x00, 0x63, 0xa3, 0x20,
-       0xc7, 0x00, 0x92, 0xa9, 0x62, 0x68, 0xd8, 0xad, 0x42, 0xef, 0xd0, 0x9d, 0x03, 0xa2, 0x5d, 0xda,
-       0x7a, 0x99, 0x9a, 0xb2, 0xa8, 0xb9, 0x8c, 0x45, 0xe4, 0x33, 0x08, 0xd8, 0xad, 0x4e, 0x06, 0x54,
-       0x0d, 0x70, 0x48, 0x75, 0x0f, 0x9f, 0xdd, 0x6a, 0xf3, 0x11, 0x3d, 0x85, 0xdd, 0x7b, 0x60, 0x99,
-       0x5d, 0xea, 0x73, 0x3d, 0xa2, 0x63, 0xec, 0x70, 0x2b, 0xb6, 0x52, 0xf4, 0x9f, 0x03, 0xee, 0x55,
-       0x71, 0x4b, 0x9e, 0x80, 0xaf, 0x90, 0x9a, 0x2a, 0x74, 0xb0, 0x3a, 0xe4, 0x40, 0x8d, 0xb2, 0x71,
-       0x65, 0x27, 0x47, 0xe0, 0xbf, 0xe5, 0xbf, 0x50, 0xd9, 0xe6, 0x6a, 0x75, 0x57, 0xd4, 0x4a, 0x7e,
-       0x80, 0xfd, 0xdf, 0xb8, 0xce, 0x99, 0x52, 0x49, 0x36, 0xe3, 0x6a, 0x85, 0xd0, 0xfe, 0xb4, 0x86,
-       0x1a, 0x91, 0xe3, 0x3d, 0x7b, 0xa2, 0xa6, 0x53, 0xe4, 0x29, 0xec, 0x56, 0x81, 0xa8, 0xbc, 0x29,
-       0x46, 0x2c, 0xd7, 0x2a, 0x6c, 0x1e, 0xba, 0x8f, 0xb7, 0xe2, 0x1d, 0x6b, 0xb8, 0xa8, 0xf4, 0xd1,
-       0x3f, 0x0e, 0x34, 0x7f, 0xc4, 0xd5, 0xa8, 0xf5, 0xe2, 0xac, 0xd9, 0x4b, 0x63, 0x55, 0x2f, 0x4b,
-       0x4b, 0x70, 0x97, 0x97, 0x40, 0xbe, 0x82, 0xbd, 0xa9, 0x73, 0x9e, 0x0e, 0x84, 0x64, 0xd9, 0x32,
-       0x16, 0x57, 0x11, 0x2f, 0xac, 0x4f, 0x2f, 0x8b, 0x04, 0x04, 0xdf, 0x0a, 0x9e, 0xf7, 0xa9, 0x62,
-       0xe4, 0xbb, 0x59, 0x94, 0x1a, 0x7c, 0xb6, 0x95, 0xe5, 0xe8, 0x91, 0xfb, 0xe8, 0x19, 0xf2, 0x53,
-       0xd9, 0xe7, 0x5a, 0x52, 0xf9, 0xbb, 0xbd, 0xed, 0x66, 0x8a, 0xe8, 0x8d, 0x03, 0xad, 0x9f, 0x0a,
-       0x3d, 0x2e, 0x34, 0x39, 0x86, 0x56, 0xb9, 0x05, 0x36, 0xc5, 0xbd, 0x25, 0xb1, 0x66, 0xf2, 0x1c,
-       0xba, 0xa9, 0xc8, 0xb5, 0x14, 0xc3, 0xb7, 0xdd, 0x21, 0xdb, 0xd6, 0x67, 0xad, 0x2b, 0x64, 0x6e,
-       0x08, 0xde, 0xaa, 0x21, 0x84, 0xe0, 0x0b, 0x99, 0xf1, 0x9c, 0x0e, 0x91, 0x42, 0x5e, 0x5c, 0x89,
-       0xd1, 0x1f, 0x0e, 0x40, 0xcc, 0x34, 0x97, 0xcc, 0x4c, 0x60, 0xfd, 0x56, 0xaa, 0xa2, 0x1a, 0xef,
-       0x2c, 0xca, 0x5d, 0xa3, 0x28, 0x6f, 0xbe, 0xa8, 0xbf, 0x5d, 0x08, 0x7a, 0xf6, 0x22, 0x25, 0x47,
-       0xd0, 0x2e, 0x77, 0x61, 0xd9, 0x35, 0x1d, 0x94, 0xa6, 0x5e, 0xb6, 0xee, 0x65, 0xf5, 0x01, 0xc0,
-       0x5c, 0xb1, 0x5e, 0xcd, 0x0d, 0xd7, 0xeb, 0x0a, 0xc2, 0xe9, 0xae, 0xe3, 0x0b, 0x27, 0x9b, 0xbe,
-       0x50, 0xec, 0x5f, 0x6c, 0x6f, 0xda, 0xc3, 0xec, 0xf1, 0x12, 0x3f, 0xa8, 0x76, 0x7f, 0xe1, 0x51,
-       0xb3, 0x94, 0x67, 0xfe, 0x66, 0x3c, 0x0b, 0xde, 0xc9, 0xb3, 0xfa, 0xd0, 0xda, 0xf3, 0x43, 0x7b,
-       0xd3, 0x80, 0xe6, 0xf5, 0x98, 0xe5, 0x19, 0x39, 0x85, 0xae, 0x1a, 0xb3, 0x5c, 0x27, 0x02, 0xf9,
-       0xb1, 0x6c, 0x6e, 0x9f, 0xa0, 0x43, 0xc9, 0x9f, 0xf2, 0x16, 0x7e, 0xdf, 0x6d, 0x5a, 0x31, 0x15,
-       0x6f, 0xc3, 0xa9, 0x6c, 0xf2, 0xc7, 0x5c, 0x05, 0x63, 0x6b, 0x23, 0x18, 0xfd, 0x39, 0x18, 0xfb,
-       0x2d, 0x7c, 0xdb, 0x9f, 0xff, 0x1f, 0x00, 0x00, 0xff, 0xff, 0x6f, 0xfd, 0x0b, 0x55, 0xe7, 0x0b,
-       0x00, 0x00,
+       0x10, 0x06, 0x45, 0x4a, 0xa4, 0xc6, 0xae, 0x25, 0xad, 0x9d, 0x94, 0x08, 0x12, 0xc0, 0x60, 0xe1,
+       0x3a, 0x45, 0x00, 0xc3, 0xb1, 0xd3, 0xa2, 0x87, 0x1e, 0xea, 0xd6, 0x6d, 0xa3, 0x83, 0xdb, 0x82,
+       0x0e, 0x72, 0x25, 0x56, 0xe4, 0xc6, 0x5a, 0x54, 0xe2, 0xaa, 0xbb, 0x4b, 0xd5, 0xf5, 0x63, 0xf4,
+       0xda, 0x73, 0x5f, 0xa0, 0xc7, 0x9e, 0xf3, 0x10, 0x7d, 0x8e, 0x3e, 0x41, 0xc1, 0xe1, 0x92, 0xa2,
+       0xfe, 0x12, 0x09, 0x49, 0x6e, 0x9c, 0x1f, 0xce, 0xcf, 0x37, 0xf3, 0xed, 0x2e, 0x78, 0x83, 0xf8,
+       0x64, 0x22, 0x85, 0x16, 0xa4, 0x31, 0x88, 0x83, 0xef, 0xc1, 0x79, 0x4e, 0xd5, 0x90, 0xec, 0x41,
+       0x63, 0x7a, 0xea, 0x5b, 0x87, 0xd6, 0xe3, 0x56, 0xd8, 0x98, 0x9e, 0xa2, 0xfc, 0xd4, 0x6f, 0x18,
+       0xf9, 0x29, 0xca, 0x67, 0xbe, 0x6d, 0xe4, 0x33, 0x94, 0xcf, 0x7d, 0xc7, 0xc8, 0xe7, 0xc1, 0x57,
+       0xe0, 0xfe, 0x2c, 0xc5, 0x8d, 0xa4, 0x63, 0xf2, 0x08, 0x60, 0x3a, 0x8e, 0xa6, 0x4c, 0x2a, 0x2e,
+       0x52, 0x0c, 0xe9, 0x84, 0xed, 0xe9, 0xf8, 0x65, 0xa1, 0x20, 0x04, 0x9c, 0x58, 0x24, 0x0c, 0x63,
+       0xef, 0x86, 0xf8, 0x1d, 0xf4, 0xc1, 0xbd, 0x50, 0x8a, 0xe9, 0xfe, 0xe5, 0x3b, 0x17, 0x72, 0x05,
+       0x3b, 0x18, 0xea, 0x62, 0x2c, 0xb2, 0x54, 0x93, 0x4f, 0xc1, 0xa3, 0xb9, 0x18, 0xf1, 0x04, 0x83,
+       0xee, 0x9c, 0xed, 0x9c, 0x0c, 0xe2, 0x13, 0x93, 0x2d, 0x74, 0xd1, 0xd8, 0x4f, 0xc8, 0x7d, 0x68,
+       0x51, 0xfc, 0x03, 0x53, 0x39, 0xa1, 0x91, 0x82, 0x3f, 0x2d, 0xe8, 0xa0, 0xf3, 0x25, 0x7b, 0xc5,
+       0x53, 0xae, 0xf3, 0x0e, 0xce, 0xa0, 0x8b, 0x9f, 0x74, 0x14, 0x0d, 0x46, 0x22, 0xfe, 0x65, 0x16,
+       0xdb, 0xcb, 0x63, 0xe7, 0x78, 0x86, 0x7b, 0xc6, 0xe3, 0x9b, 0xdc, 0xa1, 0x9f, 0x90, 0x2f, 0xa0,
+       0xcb, 0x95, 0xca, 0x68, 0x1a, 0xb3, 0x68, 0x52, 0x00, 0x85, 0x99, 0x4c, 0x3d, 0x06, 0xbb, 0xb0,
+       0x53, 0x3a, 0x95, 0x60, 0x3e, 0x04, 0x27, 0xa1, 0x9a, 0x62, 0xc3, 0xf5, 0xf8, 0xa8, 0x0d, 0x46,
+       0xb0, 0xf3, 0x92, 0x8e, 0x32, 0x76, 0x2d, 0x32, 0x19, 0x33, 0xf2, 0x00, 0x6c, 0xc9, 0x5e, 0x2d,
+       0xd5, 0x92, 0x2b, 0xc9, 0x11, 0x34, 0xa7, 0xb9, 0xab, 0xc9, 0xda, 0xa9, 0x50, 0x28, 0x80, 0x0a,
+       0x0b, 0x2b, 0x79, 0x00, 0xde, 0x44, 0x28, 0xec, 0x13, 0x73, 0x3a, 0x61, 0x25, 0x07, 0xbf, 0x42,
+       0x17, 0xb3, 0x5d, 0x32, 0xa5, 0x79, 0x4a, 0x11, 0x8b, 0x0f, 0x9c, 0xf2, 0x2f, 0x1b, 0x76, 0x10,
+       0xc2, 0xe7, 0x8c, 0x26, 0x4c, 0x12, 0x1f, 0xdc, 0xf9, 0xc5, 0x2a, 0x45, 0x72, 0x0c, 0x1d, 0xc5,
+       0x24, 0xa7, 0x23, 0x7e, 0xc7, 0x92, 0x48, 0xf1, 0x3b, 0x66, 0x26, 0xb9, 0x37, 0x53, 0x5f, 0xf3,
+       0x3b, 0x96, 0x4f, 0x7a, 0xc8, 0xf8, 0xcd, 0x50, 0x9b, 0x64, 0x46, 0x22, 0xcf, 0xa0, 0x37, 0x91,
+       0x6c, 0xca, 0x45, 0xa6, 0x66, 0x63, 0x75, 0x16, 0xfa, 0xea, 0x94, 0x2e, 0xe5, 0x5c, 0x1f, 0x42,
+       0x5b, 0xf3, 0x31, 0x53, 0x9a, 0x8e, 0x27, 0x7e, 0xb3, 0xd8, 0xf5, 0x4a, 0x41, 0x3e, 0x87, 0x9e,
+       0x96, 0x34, 0x55, 0x34, 0xce, 0xbb, 0x51, 0x91, 0x14, 0x42, 0xfb, 0xad, 0x85, 0x98, 0xdd, 0xba,
+       0x4b, 0x28, 0x84, 0x26, 0x5f, 0xc3, 0xc7, 0x35, 0x5d, 0xa4, 0x34, 0xd5, 0x99, 0x8a, 0x86, 0x54,
+       0x0d, 0x7d, 0x77, 0xe1, 0xe7, 0x7b, 0x35, 0xc7, 0x6b, 0xf4, 0x43, 0x3a, 0x1f, 0x40, 0x33, 0x15,
+       0x69, 0xcc, 0x7c, 0x0f, 0x4b, 0x2a, 0x84, 0x9c, 0x7a, 0x03, 0xae, 0x95, 0xdf, 0x46, 0x25, 0x7e,
+       0x93, 0x4b, 0x20, 0xcb, 0xb9, 0x7c, 0xc0, 0x34, 0xf7, 0xf2, 0x34, 0x2f, 0x16, 0x13, 0x84, 0xbd,
+       0xa5, 0x9c, 0xc1, 0xbf, 0x16, 0x78, 0x2f, 0x6e, 0xdf, 0xdf, 0x90, 0x1e, 0x01, 0xe4, 0x28, 0x46,
+       0x92, 0xa6, 0x37, 0xcc, 0x0c, 0x0a, 0x71, 0x0d, 0x73, 0x05, 0x39, 0x06, 0x90, 0x4c, 0x65, 0xa3,
+       0x9c, 0xd6, 0xca, 0x77, 0x0e, 0xed, 0x39, 0x4c, 0xda, 0x85, 0xad, 0x9f, 0xa8, 0x8a, 0x3e, 0xcd,
+       0x55, 0xf4, 0x21, 0x9f, 0x80, 0xc7, 0x6e, 0x75, 0x01, 0xec, 0xe2, 0x54, 0x5c, 0x76, 0xab, 0xf3,
+       0x8f, 0xe0, 0x09, 0xf4, 0x96, 0x20, 0xc8, 0x97, 0x68, 0xc0, 0xf5, 0x98, 0x4e, 0xb0, 0xc3, 0xdd,
+       0xd0, 0x48, 0xc1, 0x7f, 0x16, 0xd8, 0x57, 0xd9, 0x2d, 0xf9, 0x0c, 0x5c, 0x85, 0x9c, 0x54, 0xbe,
+       0x85, 0xd5, 0xe1, 0xf2, 0xd7, 0xb8, 0x1a, 0x96, 0x76, 0x72, 0x04, 0xee, 0x1b, 0x0e, 0x84, 0xd2,
+       0x36, 0x57, 0xab, 0xbd, 0xa6, 0x56, 0xf2, 0x03, 0x1c, 0xfc, 0xc6, 0x75, 0xca, 0x94, 0x8a, 0x92,
+       0x19, 0x49, 0x4b, 0x84, 0x0e, 0xaa, 0x1a, 0x6a, 0x0c, 0x0e, 0xf7, 0xcd, 0x1f, 0x35, 0x9d, 0x22,
+       0x4f, 0xa0, 0x57, 0x06, 0xa2, 0xf2, 0x26, 0x1b, 0xb3, 0x54, 0x2b, 0xbf, 0x79, 0x68, 0x3f, 0xde,
+       0x0d, 0xbb, 0xc6, 0x70, 0x51, 0xea, 0x83, 0x7f, 0x2c, 0x68, 0xfe, 0x88, 0x0b, 0x56, 0xeb, 0xc5,
+       0xda, 0xb0, 0x97, 0xc6, 0xba, 0x5e, 0x56, 0x96, 0x60, 0xaf, 0x2e, 0x81, 0x7c, 0x09, 0xfb, 0x95,
+       0x73, 0x1a, 0x0f, 0x85, 0x64, 0xc9, 0x2a, 0xfa, 0x96, 0x11, 0x2f, 0x8c, 0x4f, 0x3f, 0x09, 0x04,
+       0x78, 0xdf, 0x0a, 0x9e, 0x0e, 0xa8, 0x62, 0xe4, 0xbb, 0x59, 0x94, 0x1a, 0x7c, 0xa6, 0x95, 0xd5,
+       0xe8, 0x91, 0x65, 0xf4, 0xf2, 0x33, 0x81, 0xca, 0x01, 0xd7, 0x92, 0xca, 0xdf, 0xcd, 0x35, 0x37,
+       0x53, 0x04, 0xaf, 0x2d, 0x68, 0xfd, 0x94, 0xe9, 0x49, 0xa6, 0xc9, 0x31, 0xb4, 0x8a, 0x2d, 0x30,
+       0x29, 0x96, 0x96, 0xc4, 0x98, 0xc9, 0x33, 0xe8, 0xc4, 0x22, 0xd5, 0x52, 0x8c, 0xde, 0x74, 0x79,
+       0xec, 0x19, 0x9f, 0x8d, 0xee, 0x8e, 0xb9, 0x21, 0x38, 0xeb, 0x86, 0xe0, 0x83, 0x2b, 0x64, 0xc2,
+       0x53, 0x3a, 0x32, 0x87, 0x5b, 0x29, 0x06, 0x7f, 0x58, 0x00, 0x21, 0xd3, 0x5c, 0xb2, 0x7c, 0x02,
+       0x9b, 0xb7, 0x52, 0x16, 0xd5, 0x78, 0x6b, 0x51, 0xf6, 0x06, 0x45, 0x39, 0xf3, 0x45, 0xfd, 0x6d,
+       0x83, 0xd7, 0x37, 0x37, 0x28, 0x39, 0x82, 0x76, 0xb1, 0x0b, 0xab, 0xee, 0x67, 0xaf, 0x30, 0xf5,
+       0x93, 0x4d, 0x6f, 0xa9, 0xf7, 0x00, 0xe6, 0x9a, 0xf5, 0x6a, 0x6e, 0xb9, 0x5e, 0x57, 0xe0, 0x57,
+       0xbb, 0x8e, 0x4f, 0x9b, 0xa4, 0x7a, 0x9a, 0x98, 0x53, 0x6c, 0xbf, 0xea, 0x61, 0xf6, 0x6a, 0x09,
+       0xef, 0x97, 0xbb, 0xbf, 0xf0, 0x9a, 0x59, 0xc9, 0x33, 0x77, 0x3b, 0x9e, 0x79, 0x6f, 0xe5, 0x59,
+       0x7d, 0x68, 0xed, 0xf9, 0xa1, 0xbd, 0x6e, 0x40, 0xf3, 0x7a, 0xc2, 0xd2, 0x84, 0x9c, 0x42, 0x47,
+       0x4d, 0x58, 0xaa, 0x23, 0x81, 0xfc, 0x58, 0x35, 0xb7, 0x8f, 0xd0, 0xa1, 0xe0, 0x0f, 0x5e, 0xbf,
+       0xef, 0xbc, 0x4d, 0x6b, 0xa6, 0xe2, 0x6c, 0x39, 0x95, 0x6d, 0x4e, 0xcc, 0x75, 0x30, 0xb6, 0xb6,
+       0x82, 0xd1, 0x9d, 0x83, 0x71, 0xd0, 0xc2, 0x47, 0xfd, 0xf9, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff,
+       0xd9, 0xb1, 0xcb, 0x7e, 0xe0, 0x0b, 0x00, 0x00,
 }
index 51d413f..74c6dc9 100644 (file)
@@ -50,17 +50,16 @@ message ValueDestination {
 }
 
 message BlockHeader {
-  uint64            version            = 1;
-  uint64            serialized_size    = 2;
-  uint64            height             = 3;
-  Hash              previous_block_id  = 4;
-  Hash              seed               = 5;
-  uint64            timestamp          = 6;
-  Hash              transactions_root  = 7;
-  Hash              assets_root        = 8;
-  TransactionStatus transaction_status = 9;
-  uint64            nonce              = 10;
-  uint64            bits               = 11;
+  uint64            version                 = 1;
+  uint64            serialized_size         = 2;
+  uint64            height                  = 3;
+  Hash              previous_block_id       = 4;
+  uint64            timestamp               = 5;
+  Hash              transactions_root       = 6;
+  Hash              transaction_status_hash = 7;
+  uint64            nonce                   = 8;
+  uint64            bits                    = 9;
+  TransactionStatus transaction_status      = 10;
 }
 
 message TxHeader {
index 9cb74b5..34c5ccf 100644 (file)
@@ -10,28 +10,25 @@ func (bh *BlockHeader) writeForHash(w io.Writer) {
        mustWriteForHash(w, bh.Version)
        mustWriteForHash(w, bh.Height)
        mustWriteForHash(w, bh.PreviousBlockId)
-       mustWriteForHash(w, bh.Seed)
        mustWriteForHash(w, bh.Timestamp)
        mustWriteForHash(w, bh.TransactionsRoot)
-       mustWriteForHash(w, bh.AssetsRoot)
-       mustWriteForHash(w, bh.Nonce)
+       mustWriteForHash(w, bh.TransactionStatusHash)
        mustWriteForHash(w, bh.Bits)
-       mustWriteForHash(w, bh.TransactionStatus)
+       mustWriteForHash(w, bh.Nonce)
 }
 
 // NewBlockHeader creates a new BlockHeader and populates
 // its body.
-func NewBlockHeader(version, height uint64, previousBlockID, seed *Hash, timestamp uint64, transactionsRoot, assetsRoot *Hash, ts *TransactionStatus, nonce, bits uint64) *BlockHeader {
+func NewBlockHeader(version, height uint64, previousBlockID *Hash, timestamp uint64, transactionsRoot, transactionStatusHash *Hash, nonce, bits uint64) *BlockHeader {
        return &BlockHeader{
-               Version:           version,
-               Height:            height,
-               PreviousBlockId:   previousBlockID,
-               Seed:              seed,
-               Timestamp:         timestamp,
-               TransactionsRoot:  transactionsRoot,
-               AssetsRoot:        assetsRoot,
-               TransactionStatus: ts,
-               Nonce:             nonce,
-               Bits:              bits,
+               Version:               version,
+               Height:                height,
+               PreviousBlockId:       previousBlockID,
+               Timestamp:             timestamp,
+               TransactionsRoot:      transactionsRoot,
+               TransactionStatusHash: transactionStatusHash,
+               TransactionStatus:     nil,
+               Bits:                  bits,
+               Nonce:                 nonce,
        }
 }
index 45471be..9543503 100644 (file)
@@ -7,24 +7,22 @@ import (
        "github.com/bytom/protocol/bc"
 )
 
-// BlockCommitment store the TransactionsMerkleRoot && AssetsMerkleRoot
+// BlockCommitment store the TransactionsMerkleRoot && TransactionStatusHash
 type BlockCommitment struct {
        // TransactionsMerkleRoot is the root hash of the Merkle binary hash
        // tree formed by the hashes of all transactions included in the
        // block.
        TransactionsMerkleRoot bc.Hash `json:"transaction_merkle_root"`
 
-       // AssetsMerkleRoot is the root hash of the Merkle Patricia Tree of
-       // the set of unspent outputs with asset version 1 after applying
-       // the block.
-       AssetsMerkleRoot bc.Hash `json:"asset_merkle_root"`
+       // TransactionStatusHash is the hash of transaction status bitmap
+       TransactionStatusHash bc.Hash `json:"transaction_status_hash"`
 }
 
 func (bc *BlockCommitment) readFrom(r *blockchain.Reader) error {
        if _, err := bc.TransactionsMerkleRoot.ReadFrom(r); err != nil {
                return err
        }
-       _, err := bc.AssetsMerkleRoot.ReadFrom(r)
+       _, err := bc.TransactionStatusHash.ReadFrom(r)
        return err
 }
 
@@ -33,7 +31,7 @@ func (bc *BlockCommitment) writeTo(w io.Writer) error {
        if err != nil {
                return err
        }
-       _, err = bc.AssetsMerkleRoot.WriteTo(w)
+       _, err = bc.TransactionStatusHash.WriteTo(w)
        if err != nil {
                return err
        }
index 9e8909e..59f001d 100644 (file)
@@ -22,13 +22,9 @@ type BlockHeader struct {
        // Hash of the previous block in the block chain.
        PreviousBlockHash bc.Hash `json:"previous_block_hash"`
 
-       Seed bc.Hash `json:"seed"`
-
        // Time of the block in seconds.
        Timestamp uint64 `json:"timestamp"`
 
-       TransactionStatus bc.TransactionStatus `json:"transaction_status"`
-
        BlockCommitment
 
        Nonce uint64 `json:"nonce"`
@@ -78,18 +74,12 @@ func (bh *BlockHeader) readFrom(r *blockchain.Reader) (serflag uint8, err error)
        if _, err = bh.PreviousBlockHash.ReadFrom(r); err != nil {
                return 0, err
        }
-       if _, err = bh.Seed.ReadFrom(r); err != nil {
-               return 0, err
-       }
        if bh.Timestamp, err = blockchain.ReadVarint63(r); err != nil {
                return 0, err
        }
        if _, err = blockchain.ReadExtensibleString(r, bh.BlockCommitment.readFrom); err != nil {
                return 0, err
        }
-       if _, err = blockchain.ReadExtensibleString(r, bh.TransactionStatus.ReadFrom); err != nil {
-               return 0, err
-       }
        if bh.Nonce, err = blockchain.ReadVarint63(r); err != nil {
                return 0, err
        }
@@ -119,18 +109,12 @@ func (bh *BlockHeader) writeTo(w io.Writer, serflags uint8) (err error) {
        if _, err = bh.PreviousBlockHash.WriteTo(w); err != nil {
                return err
        }
-       if _, err = bh.Seed.WriteTo(w); err != nil {
-               return err
-       }
        if _, err = blockchain.WriteVarint63(w, bh.Timestamp); err != nil {
                return err
        }
        if _, err = blockchain.WriteExtensibleString(w, nil, bh.BlockCommitment.writeTo); err != nil {
                return err
        }
-       if _, err = blockchain.WriteExtensibleString(w, nil, bh.TransactionStatus.WriteTo); err != nil {
-               return err
-       }
        if _, err = blockchain.WriteVarint63(w, bh.Nonce); err != nil {
                return err
        }
index 7cece43..7afe8f8 100644 (file)
@@ -41,13 +41,10 @@ func TestMarshalBlock(t *testing.T) {
                "01" + // version
                "01" + // block height
                "0000000000000000000000000000000000000000000000000000000000000000" + // prev block hash
-               "0000000000000000000000000000000000000000000000000000000000000000" + // seed hash
                "00" + // timestamp
                "40" + // commitment extensible field length
                "0000000000000000000000000000000000000000000000000000000000000000" + // tx merkle root
-               "0000000000000000000000000000000000000000000000000000000000000000" + // assets merkle root
-               "01" + // tx status
-               "00" +
+               "0000000000000000000000000000000000000000000000000000000000000000" + // tx status root
                "00" + // nonce
                "00" + // bits
 
@@ -102,13 +99,10 @@ func TestEmptyBlock(t *testing.T) {
                "01" + // version
                "01" + // block height
                "0000000000000000000000000000000000000000000000000000000000000000" + // prev block hash
-               "0000000000000000000000000000000000000000000000000000000000000000" + // seed hash
                "00" + // timestamp
                "40" + // commitment extensible field length
                "0000000000000000000000000000000000000000000000000000000000000000" + // transactions merkle root
-               "0000000000000000000000000000000000000000000000000000000000000000" + // assets merkle root
-               "01" + // tx status
-               "00" +
+               "0000000000000000000000000000000000000000000000000000000000000000" + // tx status hash
                "00" + // nonce
                "00" + // bits
                "00") // num transactions
@@ -122,13 +116,10 @@ func TestEmptyBlock(t *testing.T) {
                "01" + // version
                "01" + // block height
                "0000000000000000000000000000000000000000000000000000000000000000" + // prev block hash
-               "0000000000000000000000000000000000000000000000000000000000000000" + // seed hash
                "00" + // timestamp
                "40" + // commitment extensible field length
                "0000000000000000000000000000000000000000000000000000000000000000" + // transactions merkle root
-               "0000000000000000000000000000000000000000000000000000000000000000" + // assets merkle root
-               "01" + // tx status
-               "00" +
+               "0000000000000000000000000000000000000000000000000000000000000000" + // tx status hash
                "00" + // nonce
                "00") // bits
        want, _ = hex.DecodeString(wantHex)
@@ -136,7 +127,7 @@ func TestEmptyBlock(t *testing.T) {
                t.Errorf("empty block header bytes = %x want %x", got, want)
        }
 
-       wantHash := mustDecodeHash("8ba2dd5c6f88f8e95e7647b9342ae473eff81105927b18832c2c884ab673b582")
+       wantHash := mustDecodeHash("a950a33eb49913c06c0c5c0aa643bb55c5cd898f3b54e91971f07ca2123d7204")
        if h := block.Hash(); h != wantHash {
                t.Errorf("got block hash %x, want %x", h.Bytes(), wantHash.Bytes())
        }
@@ -161,13 +152,10 @@ func TestSmallBlock(t *testing.T) {
                "01" + // version
                "01" + // block height
                "0000000000000000000000000000000000000000000000000000000000000000" + // prev block hash
-               "0000000000000000000000000000000000000000000000000000000000000000" + // seed hash
                "00" + // timestamp
                "40" + // commitment extensible field length
                "0000000000000000000000000000000000000000000000000000000000000000" + // transactions merkle root
-               "0000000000000000000000000000000000000000000000000000000000000000" + // assets merkle root
-               "01" + // tx status
-               "00" +
+               "0000000000000000000000000000000000000000000000000000000000000000" + // tx status hash
                "00" + // nonce
                "00" + // bits
                "01" + // num transactions
index 0246857..4d165d9 100644 (file)
@@ -241,7 +241,7 @@ func mapTx(tx *TxData) (headerID bc.Hash, hdr *bc.TxHeader, entryMap map[bc.Hash
 }
 
 func mapBlockHeader(old *BlockHeader) (bhID bc.Hash, bh *bc.BlockHeader) {
-       bh = bc.NewBlockHeader(old.Version, old.Height, &old.PreviousBlockHash, &old.Seed, old.Timestamp, &old.TransactionsMerkleRoot, &old.AssetsMerkleRoot, &old.TransactionStatus, old.Nonce, old.Bits)
+       bh = bc.NewBlockHeader(old.Version, old.Height, &old.PreviousBlockHash, old.Timestamp, &old.TransactionsMerkleRoot, &old.TransactionStatusHash, old.Nonce, old.Bits)
        bhID = bc.EntryID(bh)
        return
 }
index d6c3811..cc1ae5c 100644 (file)
@@ -21,6 +21,14 @@ func NewTransactionStatus() *TransactionStatus {
        }
 }
 
+func (TransactionStatus) typ() string {
+       return "transaction_status"
+}
+
+func (ts *TransactionStatus) writeForHash(w io.Writer) {
+       mustWriteForHash(w, ts.Bitmap)
+}
+
 func (ts *TransactionStatus) SetStatus(i int, gasOnly bool) error {
        if i >= maxBitmapSize {
                return errOverRange
index de8dcd7..b8cc4dc 100755 (executable)
@@ -40,18 +40,6 @@ func (c *Chain) GetBlockByHeight(height uint64) (*legacy.Block, error) {
        return c.GetBlockByHash(hash)
 }
 
-// ValidateBlock validates an incoming block in advance of applying it
-// to a snapshot (with ApplyValidBlock) and committing it to the
-// blockchain (with CommitAppliedBlock).
-func (c *Chain) ValidateBlock(block, prev *legacy.Block) error {
-       blockEnts := legacy.MapBlock(block)
-       prevEnts := legacy.MapBlock(prev)
-       if err := validation.ValidateBlock(blockEnts, prevEnts); err != nil {
-               return errors.Sub(ErrBadBlock, err)
-       }
-       return nil
-}
-
 // ConnectBlock append block to end of chain
 func (c *Chain) ConnectBlock(block *legacy.Block) error {
        c.state.cond.L.Lock()
@@ -59,9 +47,13 @@ func (c *Chain) ConnectBlock(block *legacy.Block) error {
        return c.connectBlock(block)
 }
 
-func (c *Chain) connectBlock(block *legacy.Block) error {
+func (c *Chain) connectBlock(block *legacy.Block) (err error) {
        bcBlock := legacy.MapBlock(block)
        utxoView := state.NewUtxoViewpoint()
+       bcBlock.TransactionStatus, err = c.store.GetTransactionStatus(&bcBlock.ID)
+       if err != nil {
+               return err
+       }
 
        if err := c.store.GetTransactionsUtxo(utxoView, bcBlock.Transactions); err != nil {
                return err
@@ -131,12 +123,17 @@ func (c *Chain) reorganizeChain(block *legacy.Block) error {
 // SaveBlock will validate and save block into storage
 func (c *Chain) SaveBlock(block *legacy.Block) error {
        preBlock, _ := c.GetBlockByHash(&block.PreviousBlockHash)
-       if err := c.ValidateBlock(block, preBlock); err != nil {
-               return err
+       blockEnts := legacy.MapBlock(block)
+       prevEnts := legacy.MapBlock(preBlock)
+
+       if err := validation.ValidateBlock(blockEnts, prevEnts); err != nil {
+               return errors.Sub(ErrBadBlock, err)
        }
-       if err := c.store.SaveBlock(block); err != nil {
+
+       if err := c.store.SaveBlock(block, blockEnts.TransactionStatus); err != nil {
                return err
        }
+
        blockHash := block.Hash()
        log.WithFields(log.Fields{"height": block.Height, "hash": blockHash.String()}).Info("Block saved on disk")
        return nil
index f6d607f..b859229 100755 (executable)
@@ -35,10 +35,11 @@ type Store interface {
        GetBlock(*bc.Hash) (*legacy.Block, error)
        GetMainchain(*bc.Hash) (map[uint64]*bc.Hash, error)
        GetStoreStatus() txdb.BlockStoreStateJSON
+       GetTransactionStatus(*bc.Hash) (*bc.TransactionStatus, error)
        GetTransactionsUtxo(*state.UtxoViewpoint, []*bc.Tx) error
        GetUtxo(*bc.Hash) (*storage.UtxoEntry, error)
 
-       SaveBlock(*legacy.Block) error
+       SaveBlock(*legacy.Block, *bc.TransactionStatus) error
        SaveChainStatus(*legacy.Block, *state.UtxoViewpoint, map[uint64]*bc.Hash) error
 }
 
@@ -196,7 +197,7 @@ func (c *Chain) InMainChain(height uint64, hash bc.Hash) bool {
        return *h == hash
 }
 
-// TimestampMS returns the latest known block timestamp.
+// Timestamp returns the latest known block timestamp.
 func (c *Chain) Timestamp() uint64 {
        c.state.cond.L.Lock()
        defer c.state.cond.L.Unlock()
@@ -218,6 +219,11 @@ func (c *Chain) GetUtxo(hash *bc.Hash) (*storage.UtxoEntry, error) {
        return c.store.GetUtxo(hash)
 }
 
+// GetTransactionStatus return the transaction status of give block
+func (c *Chain) GetTransactionStatus(hash *bc.Hash) (*bc.TransactionStatus, error) {
+       return c.store.GetTransactionStatus(hash)
+}
+
 // GetTransactionsUtxo return all the utxos that related to the txs' inputs
 func (c *Chain) GetTransactionsUtxo(view *state.UtxoViewpoint, txs []*bc.Tx) error {
        return c.store.GetTransactionsUtxo(view, txs)
index 6afedc1..e03bc30 100644 (file)
@@ -92,6 +92,7 @@ var (
        errMismatchedMerkleRoot     = errors.New("mismatched merkle root")
        errMismatchedPosition       = errors.New("mismatched value source/dest positions")
        errMismatchedReference      = errors.New("mismatched reference")
+       errMismatchedTxStatus       = errors.New("mismatched transaction status")
        errMismatchedValue          = errors.New("mismatched value")
        errMisorderedBlockHeight    = errors.New("misordered block height")
        errMisorderedBlockTime      = errors.New("misordered block time")
@@ -541,6 +542,7 @@ func ValidateBlock(b, prev *bc.Block) error {
                return errWorkProof
        }
 
+       b.TransactionStatus = bc.NewTransactionStatus()
        coinbaseValue := consensus.BlockSubsidy(b.BlockHeader.Height)
        for i, tx := range b.Transactions {
                if b.Version == 1 && tx.Version != 1 {
@@ -557,9 +559,7 @@ func ValidateBlock(b, prev *bc.Block) error {
                        }
                        gasOnlyTx = true
                }
-               if status, err := b.TransactionStatus.GetStatus(i); err != nil || status != gasOnlyTx {
-                       return errWrongTransactionStatus
-               }
+               b.TransactionStatus.SetStatus(i, gasOnlyTx)
                coinbaseValue += txBTMValue
        }
 
@@ -577,6 +577,9 @@ func ValidateBlock(b, prev *bc.Block) error {
                return errors.WithDetailf(errMismatchedMerkleRoot, "computed %x, current block wants %x", txRoot.Bytes(), b.TransactionsRoot.Bytes())
        }
 
+       if bc.EntryID(b.TransactionStatus) != *b.TransactionStatusHash {
+               return errMismatchedTxStatus
+       }
        return nil
 }
 
index fd73c97..9e73d8d 100644 (file)
@@ -447,6 +447,9 @@ func TestValidateBlock(t *testing.T) {
                },
        }
 
+       txStatus := bc.NewTransactionStatus()
+       txStatusHash := bc.EntryID(txStatus)
+
        for _, c := range cases {
                txRoot, err := bc.MerkleRoot(c.block.Transactions)
                if err != nil {
@@ -455,6 +458,7 @@ func TestValidateBlock(t *testing.T) {
                }
                c.block.BlockHeader.TransactionStatus = bc.NewTransactionStatus()
                c.block.TransactionsRoot = &txRoot
+               c.block.TransactionStatusHash = &txStatusHash
 
                if err = ValidateBlock(c.block, nil); rootErr(err) != c.err {
                        t.Errorf("got error %s, want %s", err, c.err)
@@ -520,7 +524,7 @@ func TestCoinbase(t *testing.T) {
 }
 
 func TestBlockHeaderValid(t *testing.T) {
-       base := bc.NewBlockHeader(1, 1, &bc.Hash{}, &bc.Hash{}, 1, &bc.Hash{}, &bc.Hash{}, nil, 0, 0)
+       base := bc.NewBlockHeader(1, 1, &bc.Hash{}, 1, &bc.Hash{}, &bc.Hash{}, 0, 0)
        baseBytes, _ := proto.Marshal(base)
 
        var bh bc.BlockHeader