PACKAGES := $(shell go list ./... | grep -v '/vendor/' | grep -v '/crypto/ed25519/chainkd')
-
BUILD_FLAGS := -ldflags "-X github.com/bytom/bytom/version.GitCommit=`git rev-parse HEAD`"
-MINER_BINARY32 := miner-$(GOOS)_386
-MINER_BINARY64 := miner-$(GOOS)_amd64
-
BYTOMD_BINARY32 := bytomd-$(GOOS)_386
BYTOMD_BINARY64 := bytomd-$(GOOS)_amd64
VERSION := $(shell awk -F= '/Version =/ {print $$2}' version/version.go | tr -d "\" ")
-MINER_RELEASE32 := miner-$(VERSION)-$(GOOS)_386
-MINER_RELEASE64 := miner-$(VERSION)-$(GOOS)_amd64
-
BYTOMD_RELEASE32 := bytomd-$(VERSION)-$(GOOS)_386
BYTOMD_RELEASE64 := bytomd-$(VERSION)-$(GOOS)_amd64
target:
mkdir -p $@
-binary: target/$(BYTOMD_BINARY32) target/$(BYTOMD_BINARY64) target/$(BYTOMCLI_BINARY32) target/$(BYTOMCLI_BINARY64) target/$(MINER_BINARY32) target/$(MINER_BINARY64)
+binary: target/$(BYTOMD_BINARY32) target/$(BYTOMD_BINARY64) target/$(BYTOMCLI_BINARY32) target/$(BYTOMCLI_BINARY64)
ifeq ($(GOOS),windows)
release: binary
- cd target && cp -f $(MINER_BINARY32) $(MINER_BINARY32).exe
cd target && cp -f $(BYTOMD_BINARY32) $(BYTOMD_BINARY32).exe
cd target && cp -f $(BYTOMCLI_BINARY32) $(BYTOMCLI_BINARY32).exe
- cd target && md5sum $(MINER_BINARY32).exe $(BYTOMD_BINARY32).exe $(BYTOMCLI_BINARY32).exe >$(BYTOM_RELEASE32).md5
- cd target && zip $(BYTOM_RELEASE32).zip $(MINER_BINARY32).exe $(BYTOMD_BINARY32).exe $(BYTOMCLI_BINARY32).exe $(BYTOM_RELEASE32).md5
- cd target && rm -f $(MINER_BINARY32) $(BYTOMD_BINARY32) $(BYTOMCLI_BINARY32) $(MINER_BINARY32).exe $(BYTOMD_BINARY32).exe $(BYTOMCLI_BINARY32).exe $(BYTOM_RELEASE32).md5
- cd target && cp -f $(MINER_BINARY64) $(MINER_BINARY64).exe
+ cd target && md5sum $(BYTOMD_BINARY32).exe $(BYTOMCLI_BINARY32).exe >$(BYTOM_RELEASE32).md5
+ cd target && zip $(BYTOM_RELEASE32).zip $(BYTOMD_BINARY32).exe $(BYTOMCLI_BINARY32).exe $(BYTOM_RELEASE32).md5
+ cd target && rm -f $(BYTOMD_BINARY32) $(BYTOMCLI_BINARY32) $(BYTOMD_BINARY32).exe $(BYTOMCLI_BINARY32).exe $(BYTOM_RELEASE32).md5
cd target && cp -f $(BYTOMD_BINARY64) $(BYTOMD_BINARY64).exe
cd target && cp -f $(BYTOMCLI_BINARY64) $(BYTOMCLI_BINARY64).exe
- cd target && md5sum $(MINER_BINARY64).exe $(BYTOMD_BINARY64).exe $(BYTOMCLI_BINARY64).exe >$(BYTOM_RELEASE64).md5
- cd target && zip $(BYTOM_RELEASE64).zip $(MINER_BINARY64).exe $(BYTOMD_BINARY64).exe $(BYTOMCLI_BINARY64).exe $(BYTOM_RELEASE64).md5
- cd target && rm -f $(MINER_BINARY64) $(BYTOMD_BINARY64) $(BYTOMCLI_BINARY64) $(MINER_BINARY64).exe $(BYTOMD_BINARY64).exe $(BYTOMCLI_BINARY64).exe $(BYTOM_RELEASE64).md5
+ cd target && md5sum $(BYTOMD_BINARY64).exe $(BYTOMCLI_BINARY64).exe >$(BYTOM_RELEASE64).md5
+ cd target && zip $(BYTOM_RELEASE64).zip $(BYTOMD_BINARY64).exe $(BYTOMCLI_BINARY64).exe $(BYTOM_RELEASE64).md5
+ cd target && rm -f $(BYTOMD_BINARY64) $(BYTOMCLI_BINARY64) $(BYTOMD_BINARY64).exe $(BYTOMCLI_BINARY64).exe $(BYTOM_RELEASE64).md5
else
release: binary
- cd target && md5sum $(MINER_BINARY32) $(BYTOMD_BINARY32) $(BYTOMCLI_BINARY32) >$(BYTOM_RELEASE32).md5
- cd target && tar -czf $(BYTOM_RELEASE32).tgz $(MINER_BINARY32) $(BYTOMD_BINARY32) $(BYTOMCLI_BINARY32) $(BYTOM_RELEASE32).md5
- cd target && rm -f $(MINER_BINARY32) $(BYTOMD_BINARY32) $(BYTOMCLI_BINARY32) $(BYTOM_RELEASE32).md5
- cd target && md5sum $(MINER_BINARY64) $(BYTOMD_BINARY64) $(BYTOMCLI_BINARY64) >$(BYTOM_RELEASE64).md5
- cd target && tar -czf $(BYTOM_RELEASE64).tgz $(MINER_BINARY64) $(BYTOMD_BINARY64) $(BYTOMCLI_BINARY64) $(BYTOM_RELEASE64).md5
- cd target && rm -f $(MINER_BINARY64) $(BYTOMD_BINARY64) $(BYTOMCLI_BINARY64) $(BYTOM_RELEASE64).md5
+ cd target && md5sum $(BYTOMD_BINARY32) $(BYTOMCLI_BINARY32) >$(BYTOM_RELEASE32).md5
+ cd target && tar -czf $(BYTOM_RELEASE32).tgz $(BYTOMD_BINARY32) $(BYTOMCLI_BINARY32) $(BYTOM_RELEASE32).md5
+ cd target && rm -f $(BYTOMD_BINARY32) $(BYTOMCLI_BINARY32) $(BYTOM_RELEASE32).md5
+ cd target && md5sum $(BYTOMD_BINARY64) $(BYTOMCLI_BINARY64) >$(BYTOM_RELEASE64).md5
+ cd target && tar -czf $(BYTOM_RELEASE64).tgz $(BYTOMD_BINARY64) $(BYTOMCLI_BINARY64) $(BYTOM_RELEASE64).md5
+ cd target && rm -f $(BYTOMD_BINARY64) $(BYTOMCLI_BINARY64) $(BYTOM_RELEASE64).md5
endif
release-all: clean
@echo "Cleaning binaries built..."
@rm -rf cmd/bytomd/bytomd
@rm -rf cmd/bytomcli/bytomcli
- @rm -rf cmd/miner/miner
@rm -rf target
@rm -rf $(GOPATH)/bin/bytomd
@rm -rf $(GOPATH)/bin/bytomcli
target/$(BYTOMCLI_BINARY64):
CGO_ENABLED=0 GOARCH=amd64 go build $(BUILD_FLAGS) -o $@ cmd/bytomcli/main.go
-target/$(MINER_BINARY32):
- CGO_ENABLED=0 GOARCH=386 go build $(BUILD_FLAGS) -o $@ cmd/miner/main.go
-
-target/$(MINER_BINARY64):
- CGO_ENABLED=0 GOARCH=amd64 go build $(BUILD_FLAGS) -o $@ cmd/miner/main.go
-
test:
@echo "====> Running go test"
@go test -tags "network" $(PACKAGES)
ci: test functional-tests
-.PHONY: all target release-all clean test benchmark
+.PHONY: all target release-all clean test benchmark
\ No newline at end of file
Height uint64 `json:"height"`
PreviousBlockHash *bc.Hash `json:"previous_block_hash"`
Timestamp uint64 `json:"timestamp"`
- Nonce uint64 `json:"nonce"`
TransactionsMerkleRoot *bc.Hash `json:"transaction_merkle_root"`
TransactionStatusHash *bc.Hash `json:"transaction_status_hash"`
Transactions []*BlockTx `json:"transactions"`
Height: block.Height,
PreviousBlockHash: &block.PreviousBlockHash,
Timestamp: block.Timestamp,
- Nonce: block.Nonce,
TransactionsMerkleRoot: &block.TransactionsMerkleRoot,
TransactionStatusHash: &block.TransactionStatusHash,
Transactions: []*BlockTx{},
BlockHeader: types.BlockHeader{
Version: 1,
Height: 0,
- Nonce: 9253507043297,
Timestamp: 1524549600,
BlockCommitment: types.BlockCommitment{
TransactionsMerkleRoot: merkleRoot,
BlockHeader: types.BlockHeader{
Version: 1,
Height: 0,
- Nonce: 9253507043297,
Timestamp: 1528945000,
BlockCommitment: types.BlockCommitment{
TransactionsMerkleRoot: merkleRoot,
BlockHeader: types.BlockHeader{
Version: 1,
Height: 0,
- Nonce: 9253507043297,
Timestamp: 1528945000,
BlockCommitment: types.BlockCommitment{
TransactionsMerkleRoot: merkleRoot,
}
for i := uint64(0); i < block.Height/32; i++ {
- block.Nonce++
if err := store.SaveBlock(block, txStatus); err != nil {
t.Fatal(err)
}
Timestamp uint64 `protobuf:"varint,4,opt,name=timestamp" json:"timestamp,omitempty"`
TransactionsRoot *Hash `protobuf:"bytes,5,opt,name=transactions_root,json=transactionsRoot" json:"transactions_root,omitempty"`
TransactionStatusHash *Hash `protobuf:"bytes,6,opt,name=transaction_status_hash,json=transactionStatusHash" json:"transaction_status_hash,omitempty"`
- Nonce uint64 `protobuf:"varint,7,opt,name=nonce" json:"nonce,omitempty"`
- Bits uint64 `protobuf:"varint,8,opt,name=bits" json:"bits,omitempty"`
- TransactionStatus *TransactionStatus `protobuf:"bytes,9,opt,name=transaction_status,json=transactionStatus" json:"transaction_status,omitempty"`
+ TransactionStatus *TransactionStatus `protobuf:"bytes,7,opt,name=transaction_status,json=transactionStatus" json:"transaction_status,omitempty"`
}
func (m *BlockHeader) Reset() { *m = BlockHeader{} }
return nil
}
-func (m *BlockHeader) GetNonce() uint64 {
- if m != nil {
- return m.Nonce
- }
- return 0
-}
-
-func (m *BlockHeader) GetBits() uint64 {
- if m != nil {
- return m.Bits
- }
- return 0
-}
-
func (m *BlockHeader) GetTransactionStatus() *TransactionStatus {
if m != nil {
return m.TransactionStatus
func init() { proto.RegisterFile("bc.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
- // 913 bytes of a gzipped FileDescriptorProto
- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4b, 0x6f, 0x23, 0x45,
- 0x10, 0x96, 0xc7, 0xe3, 0x57, 0x39, 0x1b, 0xc7, 0x9d, 0xec, 0x32, 0x5a, 0x2d, 0x62, 0x35, 0xd2,
- 0x12, 0x10, 0x52, 0x94, 0x38, 0x0b, 0x5c, 0x38, 0x10, 0x08, 0xcb, 0xfa, 0x10, 0x2d, 0xea, 0x44,
- 0xb9, 0x8e, 0xda, 0x33, 0x6d, 0xbb, 0xc5, 0x78, 0xda, 0x74, 0xf7, 0x98, 0x6c, 0x6e, 0xfc, 0x08,
- 0x7e, 0x0b, 0x3f, 0x81, 0x13, 0xff, 0x88, 0x03, 0xea, 0x9a, 0x1e, 0x7b, 0xfc, 0xd8, 0x97, 0xd0,
- 0xde, 0x5c, 0x8f, 0xf9, 0xaa, 0xea, 0xab, 0x47, 0x1b, 0xda, 0xa3, 0xf8, 0x64, 0xae, 0xa4, 0x91,
- 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xe0, 0xeb, 0x97, 0x2c, 0x9f, 0x2f, 0x3c, 0x81, 0xdd, 0xc1, 0xe1, 0x32, 0x81, 0xd5, 0xcb, 0x46,
- 0x1f, 0x95, 0x23, 0xb3, 0xf1, 0xe2, 0xed, 0x9c, 0xb2, 0xc6, 0xee, 0x29, 0xab, 0x32, 0xd7, 0x5c,
- 0x67, 0xee, 0xef, 0x1a, 0x34, 0xae, 0xe7, 0x3c, 0x4b, 0xc8, 0x29, 0xf4, 0xf4, 0x9c, 0x67, 0x26,
- 0x92, 0x38, 0x1d, 0xab, 0xc7, 0x79, 0xc5, 0xdd, 0x03, 0x74, 0x28, 0xa6, 0x67, 0x98, 0xbc, 0x89,
- 0x18, 0xef, 0x03, 0x89, 0xd9, 0x59, 0x49, 0xfd, 0xdd, 0x95, 0xf8, 0x6b, 0x95, 0x8c, 0x9a, 0xf8,
- 0x07, 0xea, 0xfc, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x5a, 0x57, 0x4f, 0xd8, 0x4c, 0x09, 0x00,
- 0x00,
+ // 894 bytes of a gzipped FileDescriptorProto
+ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcd, 0x6e, 0xdb, 0x46,
+ 0x10, 0x86, 0x28, 0x5a, 0x92, 0x47, 0x8e, 0x65, 0xad, 0x93, 0x94, 0x08, 0x52, 0x34, 0x20, 0x90,
+ 0xba, 0x45, 0x01, 0xc3, 0x96, 0xd3, 0xf6, 0xd2, 0x43, 0xdd, 0xba, 0x69, 0x74, 0x30, 0x52, 0xac,
+ 0x0d, 0x5f, 0x89, 0x15, 0xb9, 0x92, 0x16, 0xa5, 0xb8, 0xea, 0xee, 0x52, 0x75, 0x7c, 0xeb, 0x43,
+ 0xf4, 0x59, 0xfa, 0x08, 0x3d, 0xf5, 0xd2, 0x27, 0x2a, 0x76, 0xb8, 0x14, 0xa9, 0x9f, 0xfc, 0x18,
+ 0x45, 0x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x8e, 0x05, 0x7e, 0xd3, 0x92,
+ 0xe5, 0x47, 0x09, 0x0f, 0x5b, 0x77, 0x70, 0xb8, 0x2c, 0xa0, 0xfa, 0x5e, 0xd1, 0xc7, 0xe5, 0xc8,
+ 0xac, 0x7d, 0xc7, 0xb6, 0x4e, 0xd9, 0xce, 0xf6, 0x29, 0xab, 0x33, 0xd7, 0x5a, 0x65, 0xee, 0xef,
+ 0x06, 0xec, 0x5c, 0xcd, 0x79, 0x96, 0x90, 0x13, 0xe8, 0xe9, 0x39, 0xcf, 0x4c, 0x24, 0x71, 0x3a,
+ 0xaa, 0x4f, 0x6e, 0xc5, 0xdd, 0x03, 0x74, 0x28, 0xa6, 0x67, 0x98, 0xbc, 0x8d, 0x18, 0xef, 0x9e,
+ 0xc4, 0x6c, 0xed, 0xa4, 0xf9, 0xfe, 0x4e, 0xfc, 0x95, 0x4e, 0x46, 0x2d, 0xfc, 0x5b, 0x74, 0xf6,
+ 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa8, 0x5b, 0xe6, 0xf2, 0x22, 0x09, 0x00, 0x00,
}
uint64 timestamp = 4;
Hash transactions_root = 5;
Hash transaction_status_hash = 6;
- uint64 nonce = 7;
- uint64 bits = 8;
- TransactionStatus transaction_status = 9;
+ TransactionStatus transaction_status = 7;
}
message TxHeader {
mustWriteForHash(w, bh.Timestamp)
mustWriteForHash(w, bh.TransactionsRoot)
mustWriteForHash(w, bh.TransactionStatusHash)
- mustWriteForHash(w, bh.Bits)
- mustWriteForHash(w, bh.Nonce)
}
// NewBlockHeader creates a new BlockHeader and populates
// its body.
-func NewBlockHeader(version, height uint64, previousBlockID *Hash, timestamp uint64, transactionsRoot, transactionStatusHash *Hash, nonce, bits uint64) *BlockHeader {
+func NewBlockHeader(version, height uint64, previousBlockID *Hash, timestamp uint64, transactionsRoot, transactionStatusHash *Hash) *BlockHeader {
return &BlockHeader{
Version: version,
Height: height,
TransactionsRoot: transactionsRoot,
TransactionStatusHash: transactionStatusHash,
TransactionStatus: nil,
- Bits: bits,
- Nonce: nonce,
}
}
Height uint64 // The height of the block.
PreviousBlockHash bc.Hash // The hash of the previous block.
Timestamp uint64 // The time of the block in seconds.
- Nonce uint64 // Nonce used to generate the block.
BlockCommitment
}
if _, err = blockchain.ReadExtensibleString(r, bh.BlockCommitment.readFrom); err != nil {
return 0, err
}
- if bh.Nonce, err = blockchain.ReadVarint63(r); err != nil {
- return 0, err
- }
return
}
if _, err = blockchain.WriteExtensibleString(w, nil, bh.BlockCommitment.writeTo); err != nil {
return err
}
- if _, err = blockchain.WriteVarint63(w, bh.Nonce); err != nil {
- return err
- }
return nil
}
Height: 432234,
PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
Timestamp: 1522908275,
- Nonce: 34342,
BlockCommitment: BlockCommitment{
TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
"40", // commitment extensible field length
"ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
"b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
- "a68c02", // nonce
- "ffffff838080808020", // bits
}, "")
gotHex := testutil.Serialize(t, blockHeader)
Height: 10000,
PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
Timestamp: 1528945000,
- Nonce: 9253507043297,
BlockCommitment: BlockCommitment{
TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
"40", // commitment extensible field length
"ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
"b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
- "e19f8080a88d02", // nonce
- "cc99b3808080808020", // bits
}, ""),
},
{
Height: 9223372036854775808, // Height > MaxInt64(9223372036854775807)
PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
Timestamp: 1528945000,
- Nonce: 9253507043297,
BlockCommitment: BlockCommitment{
TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
Height: 10000,
PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
Timestamp: 9223372036854775808, // Timestamp > MaxInt64(9223372036854775807)
- Nonce: 9253507043297,
- BlockCommitment: BlockCommitment{
- TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
- TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
- },
- },
- wantError: blockchain.ErrRange,
- },
- {
- blockHeader: &BlockHeader{
- Version: 1,
- Height: 20000,
- PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
- Timestamp: 1528945000,
- Nonce: 9223372036854775808, // Nonce > MaxInt64(9223372036854775807)
- BlockCommitment: BlockCommitment{
- TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
- TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
- },
- },
- wantError: blockchain.ErrRange,
- },
- {
- blockHeader: &BlockHeader{
- Version: 1,
- Height: 20000,
- PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
- Timestamp: 1528945000,
- Nonce: 9253507043297,
BlockCommitment: BlockCommitment{
TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
Height: 9223372036854775807, // MaxInt64(9223372036854775807)
PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
Timestamp: 1528945000,
- Nonce: 9253507043297,
},
wantHex: strings.Join([]string{
"01", // serialization flags
"40", // commitment extensible field length
"0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root
"0000000000000000000000000000000000000000000000000000000000000000", // tx status hash
- "e19f8080a88d02", // nonce
- "cc99b3808080808020", // bits
}, ""),
},
}
"40", // commitment extensible field length
"ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
"b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
- "e19f8080a88d02", // nonce
- "cc99b3808080808020", // bits
}, ""),
wantBlockHeader: &BlockHeader{
Version: 1,
Height: 10000,
PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
Timestamp: 1528945000,
- Nonce: 9253507043297,
BlockCommitment: BlockCommitment{
TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
"40", // commitment extensible field length
"ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
"b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
- "e19f8080a88d02", // nonce
- "cc99b3808080808020", // bits
}, ""),
wantBlockHeader: &BlockHeader{
Version: 1,
Height: 10000,
PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
Timestamp: 1528945000,
- Nonce: 9253507043297,
BlockCommitment: BlockCommitment{
TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
"40", // commitment extensible field length
"ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
"b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
- "e19f8080a88d02", // nonce
- "cc99b3808080808020", // bits
}, ""),
wantError: fmt.Errorf("unsupported serialization flags 0x02"),
},
"40", // commitment extensible field length
"ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
"b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
- "e19f8080a88d02", // nonce
- "cc99b3808080808020", // bits
}, ""),
wantError: hex.ErrLength,
},
hexBlockHeader: strings.Join([]string{
"01", // serialization flags
"01", // version
- "ffffffffffffffff7f", // block height
+ "ffffffffffffffffff", // block height
"c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
"e8b287d905", // timestamp
"40", // commitment extensible field length
"ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
"b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
- "e19f8080a88d02", // nonce
- "ffffffffffffffffff20", // bits
}, ""),
wantError: errors.New("binary: varint overflows a 64-bit integer"),
},
"40", // commitment extensible field length
"ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
"b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
- "e19f8080a88d02", // nonce
- "ffffffffffffffff80", // bits
- }, ""),
- wantError: fmt.Errorf("EOF"),
- },
- {
- hexBlockHeader: strings.Join([]string{
- "01", // serialization flags
- "01", // version
- "ffffffffffffffff7f", // block height
- "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
- "e8b287d905", // timestamp
- "40", // commitment extensible field length
- "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
- "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
- "e19f8080a88d02", // nonce
- "ffffffffffffffffff01", // bits
- }, ""),
- wantError: blockchain.ErrRange,
- },
- {
- hexBlockHeader: strings.Join([]string{
- "01", // serialization flags
- "01", // version
- "ffffffffffffffff7f", // block height
- "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
- "e8b287d905", // timestamp
- "40", // commitment extensible field length
- "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
- "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
- "e19f8080a88d02", // nonce
- "cc99b3808080808020", // bits
}, ""),
wantBlockHeader: &BlockHeader{
Version: 1,
Height: 9223372036854775807, // MaxInt64(9223372036854775807)
PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
Timestamp: 1528945000,
- Nonce: 9253507043297,
BlockCommitment: BlockCommitment{
TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
"strings"
"testing"
- "github.com/davecgh/go-spew/spew"
-
"github.com/bytom/bytom/consensus"
"github.com/bytom/bytom/encoding/blockchain"
"github.com/bytom/bytom/protocol/bc"
"github.com/bytom/bytom/testutil"
+ "github.com/davecgh/go-spew/spew"
)
func TestBlock(t *testing.T) {
"40", // commitment extensible field length
"0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root
"0000000000000000000000000000000000000000000000000000000000000000", // tx status hash
- "00", // nonce
- "00", // bits
"00", // num transactions
}, ""),
- hash: testutil.MustDecodeHash("9609d2e45760f34cbc6c6d948c3fb9b6d7b61552d9d17fdd5b7d0cb5d2e67244"),
+ hash: testutil.MustDecodeHash("ba63a0f8e9a7e5f93e3ec7ce49f07276c065bdf75e270984d9390bee0b3de027"),
},
{
block: &Block{
Height: 432234,
PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
Timestamp: 1522908275,
- Nonce: 34342,
BlockCommitment: BlockCommitment{
TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
"40", // commitment extensible field length
"ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
"b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
- "a68c02", // nonce
- "ffffff838080808020", // bits
- "02", // num transactions
+ "02", // num transactions
"07018e0502012a00056e6f6e6365a69849e11add96ac7053aad22ba2349a4abf5feb0475a0afcadff4e128be76cf92c30f380f6173736574446566696e6974696f6e010f69737375616e636550726f6772616d020a617267756d656e7473310a617267756d656e74733201540152fad5195a0c8e3b590b86a3c0a95e7529565888508aecca96e9aeda633002f409ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff92c30f03010c7370656e6450726f6772616d17020a617267756d656e7473330a617267756d656e747334010129a69849e11add96ac7053aad22ba2349a4abf5feb0475a0afcadff4e128be76cf92c30f01047472756500",
"07010001010b020961726269747261727900020129ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff92c30f01047472756500012affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff92c30f010566616c736500",
}, ""),
- hash: testutil.MustDecodeHash("86c833711a6a6b59864708d9dbae7869ba10782e3e7b1c7fc9fe3514899fec80"),
+ hash: testutil.MustDecodeHash("fca0cfd96604b0b28e4a16286974db155d0bbd42dd729d2e2ba058d09a963016"),
},
}
wantBlock Block
}{
{
- rawBlock: "03018b5f3077f24528e94ecfc4491bb2e9ed6264a632a9a4b86b00c88093ca545d14a137d4f5e1e4054035a2d11158f47a5c5267630b2b6cf9e9a5f79a598085a2572a68defeb8013ad26978a65b4ee5b6f4914fe5c05000459a803ecf59132604e5d334d64249c5e50a17ebee908080808080200207010001010802060031323137310001013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff809df3b49a010116001437e1aec83a4e6587ca9609e4e5aa728db700744900070100020160015e4b5cb973f5bef4eadde4c89b92ee73312b940e84164da0594149554cc8a2adeaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80c480c1240201160014cb9f2391bafe2bc1159b2c4c8a0f17ba1b4dd94e6302405760b15cc09e543437c4e3aad05bf073e82ebdb214beccb5f4473653dfc0a9d5ae59fb149de19eb71c1c1399594757aeea4dd6327ca2790ef919bd20caa86104201381d35e235813ad1e62f9a602c82abee90565639cc4573568206b55bcd2aed90130000840142084606f20ca7b38dc897329a288ea31031724f5c55bcafec80468a546955023380af2faad1480d0dbc3f402b001467b0a202022646563696d616c73223a20382c0a2020226465736372697074696f6e223a207b7d2c0a2020226e616d65223a2022222c0a20202273796d626f6c223a2022220a7d0125ae2054a71277cc162eb3eb21b5bd9fe54402829a53b294deaed91692a2cd8a081f9c5151ad0140621c2c3554da50d2a492d9d78be7c6159359d8f5f0b93a054ce0133617a61d85c532aff449b97a3ec2804ca5fe12b4d54aa6e8c3215c33d04abee9c9abdfdb0302013dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80c0d1e123011600144b61da45324299e40dacc255e2ea07dfce3a56d200013e7b38dc897329a288ea31031724f5c55bcafec80468a546955023380af2faad1480d0dbc3f4020116001437e1aec83a4e6587ca9609e4e5aa728db700744900",
+ rawBlock: "03018b5f3077f24528e94ecfc4491bb2e9ed6264a632a9a4b86b00c88093ca545d14a137d4f5e1e4054035a2d11158f47a5c5267630b2b6cf9e9a5f79a598085a2572a68defeb8013ad26978a65b4ee5b6f4914fe5c05000459a803ecf59132604e5d334d64249c5e50a0207010001010802060031323137310001013effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff809df3b49a010116001437e1aec83a4e6587ca9609e4e5aa728db700744900070100020160015e4b5cb973f5bef4eadde4c89b92ee73312b940e84164da0594149554cc8a2adeaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80c480c1240201160014cb9f2391bafe2bc1159b2c4c8a0f17ba1b4dd94e6302405760b15cc09e543437c4e3aad05bf073e82ebdb214beccb5f4473653dfc0a9d5ae59fb149de19eb71c1c1399594757aeea4dd6327ca2790ef919bd20caa86104201381d35e235813ad1e62f9a602c82abee90565639cc4573568206b55bcd2aed90130000840142084606f20ca7b38dc897329a288ea31031724f5c55bcafec80468a546955023380af2faad1480d0dbc3f402b001467b0a202022646563696d616c73223a20382c0a2020226465736372697074696f6e223a207b7d2c0a2020226e616d65223a2022222c0a20202273796d626f6c223a2022220a7d0125ae2054a71277cc162eb3eb21b5bd9fe54402829a53b294deaed91692a2cd8a081f9c5151ad0140621c2c3554da50d2a492d9d78be7c6159359d8f5f0b93a054ce0133617a61d85c532aff449b97a3ec2804ca5fe12b4d54aa6e8c3215c33d04abee9c9abdfdb0302013dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80c0d1e123011600144b61da45324299e40dacc255e2ea07dfce3a56d200013e7b38dc897329a288ea31031724f5c55bcafec80468a546955023380af2faad1480d0dbc3f4020116001437e1aec83a4e6587ca9609e4e5aa728db700744900",
wantBlock: Block{
BlockHeader: BlockHeader{
Version: 1,
Height: 12171,
PreviousBlockHash: testutil.MustDecodeHash("3077f24528e94ecfc4491bb2e9ed6264a632a9a4b86b00c88093ca545d14a137"),
Timestamp: 1553496788,
- Nonce: 23,
BlockCommitment: BlockCommitment{
TransactionsMerkleRoot: testutil.MustDecodeHash("35a2d11158f47a5c5267630b2b6cf9e9a5f79a598085a2572a68defeb8013ad2"),
TransactionStatusHash: testutil.MustDecodeHash("6978a65b4ee5b6f4914fe5c05000459a803ecf59132604e5d334d64249c5e50a"),
}
func mapBlockHeader(old *BlockHeader) (bc.Hash, *bc.BlockHeader) {
- bh := bc.NewBlockHeader(old.Version, old.Height, &old.PreviousBlockHash, old.Timestamp, &old.TransactionsMerkleRoot, &old.TransactionStatusHash, old.Nonce, 0)
+ bh := bc.NewBlockHeader(old.Version, old.Height, &old.PreviousBlockHash, old.Timestamp, &old.TransactionsMerkleRoot, &old.TransactionStatusHash)
return bc.EntryID(bh), bh
}
mainChainNode := initNode
for i := 1; i <= 7; i++ {
header.Height = uint64(i)
- header.Nonce = 0
mainChainNode, err = state.NewBlockNode(&header, mainChainNode)
if err != nil {
t.Fatal(err)
sideChainNode := initNode
for i := 1; i <= 13; i++ {
header.Height = uint64(i)
- header.Nonce = 1
sideChainNode, err = state.NewBlockNode(&header, sideChainNode)
if err != nil {
t.Fatal(err)
for i := uint64(1); i <= 5; i++ {
node := &state.BlockNode{
Height: i,
- Nonce: 0,
Hash: bc.Hash{V0: uint64(i)},
Parent: testNodes[i-1],
}
newNode := &state.BlockNode{
Height: i,
- Nonce: 1,
Hash: bc.Hash{V1: uint64(i)},
Parent: testNewNodes[i-1],
}
var testBlocks = []*types.Block{
{BlockHeader: types.BlockHeader{
PreviousBlockHash: bc.Hash{V0: 1},
- Nonce: 0,
+ Timestamp: 0,
}},
{BlockHeader: types.BlockHeader{
PreviousBlockHash: bc.Hash{V0: 1},
- Nonce: 1,
+ Timestamp: 1,
}},
{BlockHeader: types.BlockHeader{
PreviousBlockHash: bc.Hash{V0: 2},
- Nonce: 3,
+ Timestamp: 3,
}},
}
for i, c := range cases {
c.before.deleteLRU()
if !testutil.DeepEqual(c.before, c.after) {
- t.Errorf("case %d: got %v want %v", i, c.before, c.after)
+ t.Errorf("case %d:\n got %v\n want %v", i, c.before, c.after)
}
}
}
log "github.com/sirupsen/logrus"
"github.com/bytom/bytom/config"
- "github.com/bytom/bytom/errors"
"github.com/bytom/bytom/protocol/bc"
"github.com/bytom/bytom/protocol/bc/types"
"github.com/bytom/bytom/protocol/state"
return c.index.InMainchain(hash)
}
-// CalcNextSeed return the seed for the given block
-func (c *Chain) CalcNextSeed(preBlock *bc.Hash) (*bc.Hash, error) {
- node := c.index.GetNode(preBlock)
- if node == nil {
- return nil, errors.New("can't find preblock in the blockindex")
- }
- return node.CalcNextSeed(), nil
-}
-
func (c *Chain) GetBlockIndex() *state.BlockIndex {
return c.index
}
// BlockNode represents a block within the block chain and is primarily used to
// aid in selecting the best chain to be the main chain.
type BlockNode struct {
- Parent *BlockNode // parent is the parent block for this node.
- Hash bc.Hash // hash of the block.
- Seed *bc.Hash // seed hash of the block
-
+ Parent *BlockNode // parent is the parent block for this node.
+ Hash bc.Hash // hash of the block.
Version uint64
Height uint64
Timestamp uint64
- Nonce uint64
TransactionsMerkleRoot bc.Hash
TransactionStatusHash bc.Hash
}
Version: bh.Version,
Height: bh.Height,
Timestamp: bh.Timestamp,
- Nonce: bh.Nonce,
TransactionsMerkleRoot: bh.TransactionsMerkleRoot,
TransactionStatusHash: bh.TransactionStatusHash,
}
- if bh.Height == 0 {
- node.Seed = consensus.InitialSeed
- } else {
- node.Seed = parent.CalcNextSeed()
- }
return node, nil
}
Height: node.Height,
PreviousBlockHash: previousBlockHash,
Timestamp: node.Timestamp,
- Nonce: node.Nonce,
BlockCommitment: types.BlockCommitment{
TransactionsMerkleRoot: node.TransactionsMerkleRoot,
TransactionStatusHash: node.TransactionStatusHash,
return timestamps[len(timestamps)/2]
}
-// CalcNextSeed calculate the seed for next block
-func (node *BlockNode) CalcNextSeed() *bc.Hash {
- if node.Height == 0 {
- return consensus.InitialSeed
- }
- if node.Height%consensus.SeedPerRetarget == 0 {
- return &node.Hash
- }
- return node.Seed
-}
-
// BlockIndex is the struct for help chain trace block chain as tree
type BlockIndex struct {
sync.RWMutex
"github.com/davecgh/go-spew/spew"
- "github.com/bytom/bytom/consensus"
"github.com/bytom/bytom/protocol/bc"
"github.com/bytom/bytom/protocol/bc/types"
"github.com/bytom/bytom/testutil"
},
parentNode: &BlockNode{},
wantBlockNode: &BlockNode{
- Hash: testutil.MustDecodeHash("f1a5a6ddebad7285928a07ce1534104a8d1cd435fc80e90bb9f0034bbe5f8109"),
- Seed: consensus.InitialSeed,
+ Hash: testutil.MustDecodeHash("39dee75363127a2857f554d2ad2706eb876407a2e09fbe0338683ca4ad4c2f90"),
Parent: &BlockNode{},
},
},
},
parentNode: &BlockNode{},
wantBlockNode: &BlockNode{
- Hash: testutil.MustDecodeHash("b14067726f09d74da89aeb97ca1b15a8b95760b47a0d71549b0aa5ab8c5e724f"),
- Seed: consensus.InitialSeed,
+ Hash: testutil.MustDecodeHash("7b23bfb7e3f44022822cecb168f788bca03f9c953ab110e6f6d49e34fdeb4db5"),
Height: uint64(100),
Parent: &BlockNode{},
},
},
parentNode: &BlockNode{},
wantBlockNode: &BlockNode{
- Hash: testutil.MustDecodeHash("b14067726f09d74da89aeb97ca1b15a8b95760b47a0d71549b0aa5ab8c5e724f"),
- Seed: consensus.InitialSeed,
+ Hash: testutil.MustDecodeHash("7b23bfb7e3f44022822cecb168f788bca03f9c953ab110e6f6d49e34fdeb4db5"),
Height: uint64(100),
Parent: &BlockNode{},
},
}
}
-func TestCalcNextSeed(t *testing.T) {
- cases := []struct {
- node *BlockNode
- seed *bc.Hash
- }{
- {
- node: &BlockNode{
- Height: 0,
- },
- seed: consensus.InitialSeed,
- },
- {
- node: &BlockNode{
- Height: consensus.SeedPerRetarget - 1,
- Seed: &bc.Hash{V1: 100},
- },
- seed: &bc.Hash{V1: 100},
- },
- {
- node: &BlockNode{
- Height: consensus.SeedPerRetarget,
- Seed: &bc.Hash{V2: 200},
- Hash: bc.Hash{V3: 300},
- },
- seed: &bc.Hash{V3: 300},
- },
- }
-
- for i, c := range cases {
- seed := c.node.CalcNextSeed()
- if *seed != *c.seed {
- t.Fatalf("calc next seed failed, index: %d, expected: %v, have: %v", i, c.seed, seed)
- }
- }
-}
-
func TestSetMainChain(t *testing.T) {
blockIndex := NewBlockIndex()
var lastNode *BlockNode
type mockStore struct{}
+func (s *mockStore) GetBlockHeader(hash *bc.Hash) (*types.BlockHeader, error) {
+ panic("implement me")
+}
+
+func (s *mockStore) GetCheckpoint(hash *bc.Hash) (*state.Checkpoint, error) {
+ panic("implement me")
+}
+
+func (s *mockStore) GetCheckpointsByHeight(u uint64) ([]*state.Checkpoint, error) {
+ panic("implement me")
+}
+
func (s *mockStore) BlockExist(hash *bc.Hash) bool { return false }
func (s *mockStore) GetBlock(*bc.Hash) (*types.Block, error) { return nil, nil }
func (s *mockStore) GetStoreStatus() *BlockStoreState { return nil }
type mockStore1 struct{}
+func (s *mockStore1) GetBlockHeader(hash *bc.Hash) (*types.BlockHeader, error) {
+ panic("implement me")
+}
+
+func (s *mockStore1) GetCheckpoint(hash *bc.Hash) (*state.Checkpoint, error) {
+ panic("implement me")
+}
+
+func (s *mockStore1) GetCheckpointsByHeight(u uint64) ([]*state.Checkpoint, error) {
+ panic("implement me")
+}
+
func (s *mockStore1) BlockExist(hash *bc.Hash) bool { return false }
func (s *mockStore1) GetBlock(*bc.Hash) (*types.Block, error) { return nil, nil }
func (s *mockStore1) GetStoreStatus() *BlockStoreState { return nil }
err: errMisorderedBlockHeight,
},
{
- desc: "the difficulty of the block is not equals to the next difficulty of parent block (blocktest#1008)",
- block: &bc.Block{BlockHeader: &bc.BlockHeader{
- Version: 1,
- Height: 20,
- Bits: 0,
- }},
- parent: &state.BlockNode{
- Version: 1,
- Height: 19,
- },
- err: errBadBits,
- },
- {
desc: "the prev block hash not equals to the hash of parent (blocktest#1004)",
block: &bc.Block{BlockHeader: &bc.BlockHeader{
Version: 1,
Height: 0,
Timestamp: 1523352600,
Hash: bc.Hash{V0: 0},
- Seed: &bc.Hash{V1: 1},
},
err: nil,
},
Height: 1,
Timestamp: 1523352601,
PreviousBlockId: &bc.Hash{V0: 0},
- Bits: 2305843009214532812,
TransactionsRoot: &bc.Hash{V0: 1},
},
Transactions: []*bc.Tx{
Height: 0,
Timestamp: 1523352600,
Hash: bc.Hash{V0: 0},
- Seed: &bc.Hash{V1: 1},
},
err: errMismatchedMerkleRoot,
},
Height: 1,
Timestamp: 1523352601,
PreviousBlockId: &bc.Hash{V0: 0},
- Bits: 2305843009214532812,
TransactionsRoot: &bc.Hash{V0: 6294987741126419124, V1: 12520373106916389157, V2: 5040806596198303681, V3: 1151748423853876189},
TransactionStatusHash: &bc.Hash{V0: 1},
},
Height: 0,
Timestamp: 1523352600,
Hash: bc.Hash{V0: 0},
- Seed: &bc.Hash{V1: 1},
},
err: errMismatchedMerkleRoot,
},
Height: 0,
Timestamp: 1523352600,
Hash: bc.Hash{V0: 0},
- Seed: &bc.Hash{V1: 1},
},
err: ErrWrongCoinbaseTransaction,
},
// TestGasOverBlockLimit check if the gas of the block has the max limit (blocktest#1012)
func TestGasOverBlockLimit(t *testing.T) {
+
cp, _ := vmutil.DefaultCoinbaseProgram()
parent := &state.BlockNode{
Version: 1,
Height: 0,
Timestamp: 1523352600,
Hash: bc.Hash{V0: 0},
- Seed: &bc.Hash{V1: 1},
}
block := &bc.Block{
ID: bc.Hash{V0: 1},
Height: 1,
Timestamp: 1523352601,
PreviousBlockId: &bc.Hash{V0: 0},
- Bits: 2305843009214532812,
TransactionsRoot: &bc.Hash{V0: 1},
},
Transactions: []*bc.Tx{
// TestSetTransactionStatus verify the transaction status is set correctly (blocktest#1010)
func TestSetTransactionStatus(t *testing.T) {
+
cp, _ := vmutil.DefaultCoinbaseProgram()
parent := &state.BlockNode{
Version: 1,
Height: 0,
Timestamp: 1523352600,
Hash: bc.Hash{V0: 0},
- Seed: &bc.Hash{V1: 1},
}
block := &bc.Block{
ID: bc.Hash{V0: 1},
Height: 1,
Timestamp: 1523352601,
PreviousBlockId: &bc.Hash{V0: 0},
- Bits: 2305843009214532812,
TransactionsRoot: &bc.Hash{V0: 3413931728524254295, V1: 300490676707850231, V2: 1886132055969225110, V3: 10216139531293906088},
TransactionStatusHash: &bc.Hash{V0: 8682965660674182538, V1: 8424137560837623409, V2: 6979974817894224946, V3: 4673809519342015041},
},
package test
-// import (
-// "fmt"
-// "io/ioutil"
-// "os"
-// "testing"
-// "time"
-
-// "github.com/bytom/bytom/account"
-// "github.com/bytom/bytom/blockchain/pseudohsm"
-// "github.com/bytom/bytom/blockchain/signers"
-// "github.com/bytom/bytom/blockchain/txbuilder"
-// "github.com/bytom/bytom/consensus"
-// "github.com/bytom/bytom/crypto/ed25519/chainkd"
-// "github.com/bytom/bytom/database"
-// dbm "github.com/bytom/bytom/database/leveldb"
-// "github.com/bytom/bytom/database/storage"
-// "github.com/bytom/bytom/event"
-// "github.com/bytom/bytom/protocol"
-// "github.com/bytom/bytom/protocol/bc"
-// "github.com/bytom/bytom/protocol/bc/types"
-// "github.com/bytom/bytom/protocol/state"
-// )
-
-// func BenchmarkChain_CoinBaseTx_NoAsset(b *testing.B) {
-// benchInsertChain(b, 0, 0, "")
-// }
-
-// func BenchmarkChain_BtmTx_NoAsset_BASE(b *testing.B) {
-// benchInsertChain(b, 1, 0, "")
-// }
-
-// func BenchmarkChain_5000BtmTx_NoAsset_BASE(b *testing.B) {
-// benchInsertChain(b, 5000, 0, "")
-// }
-
-// func BenchmarkChain_5000BtmTx_1Asset_BASE(b *testing.B) {
-// benchInsertChain(b, 5000, 1, "")
-// }
-
-// // standard Transaction
-// func BenchmarkChain_BtmTx_NoAsset_P2PKH(b *testing.B) {
-// benchInsertChain(b, 1000, 0, "P2PKH")
-// }
-
-// func BenchmarkChain_BtmTx_1Asset_P2PKH(b *testing.B) {
-// benchInsertChain(b, 1000, 1, "P2PKH")
-// }
-
-// func BenchmarkChain_BtmTx_NoAsset_P2SH(b *testing.B) {
-// benchInsertChain(b, 100, 0, "P2SH")
-// }
-
-// func BenchmarkChain_BtmTx_1Asset_P2SH(b *testing.B) {
-// benchInsertChain(b, 100, 1, "P2SH")
-// }
-
-// func BenchmarkChain_BtmTx_NoAsset_MultiSign(b *testing.B) {
-// benchInsertChain(b, 100, 0, "MultiSign")
-// }
-
-// func BenchmarkChain_BtmTx_1Asset_MultiSign(b *testing.B) {
-// benchInsertChain(b, 100, 1, "MultiSign")
-// }
-
-// // func benchInsertChain(b *testing.B, blockTxNumber int, otherAssetNum int, txType string) {
-// // b.StopTimer()
-// // testNumber := b.N
-// // totalTxNumber := testNumber * blockTxNumber
-
-// // dirPath, err := ioutil.TempDir(".", "testDB")
-// // if err != nil {
-// // b.Fatal("create dirPath err:", err)
-// // }
-// // defer os.RemoveAll(dirPath)
-
-// // testDB := dbm.NewDB("testdb", "leveldb", dirPath)
-// // defer testDB.Close()
-
-// // // Generate a chain test data.
-// // chain, txs, txPool, err := GenerateChainData(dirPath, testDB, totalTxNumber, otherAssetNum, txType)
-// // if err != nil {
-// // b.Fatal("GenerateChainData err:", err)
-// // }
-
-// // b.ReportAllocs()
-// // b.StartTimer()
-
-// // for i := 0; i < b.N; i++ {
-// // testTxs := txs[blockTxNumber*i : blockTxNumber*(i+1)]
-// // if err := InsertChain(chain, txPool, testTxs); err != nil {
-// // b.Fatal("Failed to insert block into chain:", err)
-// // }
-// // }
-// // }
-
-// func GenerateChainData(dirPath string, testDB dbm.DB, txNumber, otherAssetNum int, txType string) (*protocol.Chain, []*types.Tx, *protocol.TxPool, error) {
-// var err error
-
-// // generate transactions
-// txs := []*types.Tx{}
-// switch txType {
-// case "P2PKH":
-// txs, err = MockTxsP2PKH(dirPath, testDB, txNumber, otherAssetNum)
-// if err != nil {
-// return nil, nil, nil, err
-// }
-// case "P2SH":
-// txs, err = MockTxsP2SH(dirPath, testDB, txNumber, otherAssetNum)
-// if err != nil {
-// return nil, nil, nil, err
-// }
-// case "MultiSign":
-// txs, err = MockTxsMultiSign(dirPath, testDB, txNumber, otherAssetNum)
-// if err != nil {
-// return nil, nil, nil, err
-// }
-// default:
-// txs, err = CreateTxbyNum(txNumber, otherAssetNum)
-// if err != nil {
-// return nil, nil, nil, err
-// }
-// }
-
-// // init UtxoViewpoint
-// utxoView := state.NewUtxoViewpoint()
-// utxoEntry := storage.NewUtxoEntry(false, 1, false)
-// for _, tx := range txs {
-// for _, id := range tx.SpentOutputIDs {
-// utxoView.Entries[id] = utxoEntry
-// }
-// }
-
-// if err := SetUtxoView(testDB, utxoView); err != nil {
-// return nil, nil, nil, err
-// }
-
-// store := database.NewStore(testDB)
-// dispatcher := event.NewDispatcher()
-// txPool := protocol.NewTxPool(store, dispatcher)
-// chain, err := protocol.NewChain(store, txPool)
-// if err != nil {
-// return nil, nil, nil, err
-// }
-
-// go processNewTxch(txPool)
-
-// return chain, txs, txPool, nil
-// }
-
-// // func InsertChain(chain *protocol.Chain, txPool *protocol.TxPool, txs []*types.Tx) error {
-// // for _, tx := range txs {
-// // if err := txbuilder.FinalizeTx(nil, chain, tx); err != nil {
-// // return err
-// // }
-// // }
-
-// // block, err := mining.NewBlockTemplate(chain, txPool, nil)
-// // if err != nil {
-// // return err
-// // }
-
-// // blockSize, err := block.MarshalText()
-// // if err != nil {
-// // return err
-// // }
-
-// // fmt.Println("blocksize:", uint64(len(blockSize)))
-// // fmt.Println("block tx count:", uint64(len(block.Transactions)))
-// // fmt.Println("coinbase txsize:", uint64(block.Transactions[0].SerializedSize))
-// // if len(block.Transactions) > 1 {
-// // fmt.Println("txsize:", uint64(block.Transactions[1].SerializedSize))
-// // }
-
-// // seed, err := chain.CalcNextSeed(&block.PreviousBlockHash)
-// // if err != nil {
-// // return err
-// // }
-
-// // if err := SolveBlock(seed, block); err != nil {
-// // return err
-// // }
-
-// // if _, err := chain.ProcessBlock(block); err != nil {
-// // return err
-// // }
-
-// // return nil
-// // }
-
-// func processNewTxch(txPool *protocol.TxPool) {
-// }
-
-// // func SolveBlock(seed *bc.Hash, block *types.Block) error {
-// // maxNonce := ^uint64(0) // 2^64 - 1
-// // header := &block.BlockHeader
-// // for i := uint64(0); i < maxNonce; i++ {
-// // header.Nonce = i
-// // headerHash := header.Hash()
-// // if difficulty.CheckProofOfWork(&headerHash, seed, header.Bits) {
-// // return nil
-// // }
-// // }
-// // return nil
-// // }
-
-// func MockSimpleUtxo(index uint64, assetID *bc.AssetID, amount uint64, ctrlProg *account.CtrlProgram) *account.UTXO {
-// if ctrlProg == nil {
-// ctrlProg = &account.CtrlProgram{
-// AccountID: "",
-// Address: "",
-// KeyIndex: uint64(0),
-// ControlProgram: []byte{81},
-// Change: false,
-// }
-// }
-
-// utxo := &account.UTXO{
-// OutputID: bc.Hash{V0: 1},
-// SourceID: bc.Hash{V0: 1},
-// AssetID: *assetID,
-// Amount: amount,
-// SourcePos: index,
-// ControlProgram: ctrlProg.ControlProgram,
-// ControlProgramIndex: ctrlProg.KeyIndex,
-// AccountID: ctrlProg.AccountID,
-// Address: ctrlProg.Address,
-// ValidHeight: 0,
-// }
-
-// return utxo
-// }
-
-// func GenerateBaseUtxos(num int, amount uint64, ctrlProg *account.CtrlProgram) []*account.UTXO {
-// utxos := []*account.UTXO{}
-// for i := 0; i < num; i++ {
-// utxo := MockSimpleUtxo(uint64(i), consensus.BTMAssetID, amount, ctrlProg)
-// utxos = append(utxos, utxo)
-// }
-
-// return utxos
-// }
-
-// func GenerateOtherUtxos(typeCount, num int, amount uint64, ctrlProg *account.CtrlProgram) []*account.UTXO {
-// utxos := []*account.UTXO{}
-
-// assetID := &bc.AssetID{
-// V0: uint64(typeCount),
-// V1: uint64(1),
-// V2: uint64(0),
-// V3: uint64(1),
-// }
-
-// for i := 0; i < num; i++ {
-// utxo := MockSimpleUtxo(uint64(typeCount*num+i), assetID, amount, ctrlProg)
-// utxos = append(utxos, utxo)
-// }
-
-// return utxos
-// }
-
-// func AddTxInputFromUtxo(utxo *account.UTXO, singer *signers.Signer) (*types.TxInput, *txbuilder.SigningInstruction, error) {
-// txInput, signInst, err := account.UtxoToInputs(singer, utxo)
-// if err != nil {
-// return nil, nil, err
-// }
-
-// return txInput, signInst, nil
-// }
-
-// func AddTxOutput(assetID bc.AssetID, amount uint64, controlProgram []byte) *types.TxOutput {
-// out := types.NewTxOutput(assetID, amount, controlProgram)
-// return out
-// }
-
-// func CreateTxBuilder(baseUtxo *account.UTXO, btmServiceFlag bool, signer *signers.Signer) (*txbuilder.TemplateBuilder, error) {
-// tplBuilder := txbuilder.NewBuilder(time.Now())
-
-// // add input
-// txInput, signInst, err := AddTxInputFromUtxo(baseUtxo, signer)
-// if err != nil {
-// return nil, err
-// }
-// tplBuilder.AddInput(txInput, signInst)
-
-// // if the btm is the service charge, didn't need to add the output
-// if btmServiceFlag {
-// txOutput := AddTxOutput(baseUtxo.AssetID, 100, baseUtxo.ControlProgram)
-// tplBuilder.AddOutput(txOutput)
-// }
-
-// return tplBuilder, nil
-// }
-
-// func AddTxBuilder(tplBuilder *txbuilder.TemplateBuilder, utxo *account.UTXO, signer *signers.Signer) error {
-// txInput, signInst, err := AddTxInputFromUtxo(utxo, signer)
-// if err != nil {
-// return err
-// }
-// tplBuilder.AddInput(txInput, signInst)
-
-// txOutput := AddTxOutput(utxo.AssetID, utxo.Amount, utxo.ControlProgram)
-// tplBuilder.AddOutput(txOutput)
-
-// return nil
-// }
-
-// func BuildTx(baseUtxo *account.UTXO, otherUtxos []*account.UTXO, signer *signers.Signer) (*txbuilder.Template, error) {
-// btmServiceFlag := false
-// if otherUtxos == nil || len(otherUtxos) == 0 {
-// btmServiceFlag = true
-// }
-
-// tplBuilder, err := CreateTxBuilder(baseUtxo, btmServiceFlag, signer)
-// if err != nil {
-// return nil, err
-// }
-
-// for _, u := range otherUtxos {
-// if err := AddTxBuilder(tplBuilder, u, signer); err != nil {
-// return nil, err
-// }
-// }
-
-// tpl, _, err := tplBuilder.Build()
-// if err != nil {
-// return nil, err
-// }
-
-// return tpl, nil
-// }
-
-// func GenetrateTxbyUtxo(baseUtxo []*account.UTXO, otherUtxo [][]*account.UTXO) ([]*types.Tx, error) {
-// tmpUtxo := []*account.UTXO{}
-// txs := []*types.Tx{}
-// otherUtxoFlag := true
-
-// if len(otherUtxo) == 0 || len(otherUtxo) != len(baseUtxo) {
-// otherUtxoFlag = false
-// }
-
-// for i := 0; i < len(baseUtxo); i++ {
-// if otherUtxoFlag {
-// tmpUtxo = otherUtxo[i]
-// } else {
-// tmpUtxo = nil
-// }
-
-// tpl, err := BuildTx(baseUtxo[i], tmpUtxo, nil)
-// if err != nil {
-// return nil, err
-// }
-
-// txs = append(txs, tpl.Transaction)
-// }
-
-// return txs, nil
-// }
-
-// func CreateTxbyNum(txNumber, otherAssetNum int) ([]*types.Tx, error) {
-// baseUtxos := GenerateBaseUtxos(txNumber, 1000000000, nil)
-// otherUtxos := make([][]*account.UTXO, 0, txNumber)
-// if otherAssetNum != 0 {
-// for i := 0; i < txNumber; i++ {
-// utxos := GenerateOtherUtxos(i, otherAssetNum, 6000, nil)
-// otherUtxos = append(otherUtxos, utxos)
-// }
-// }
-
-// txs, err := GenetrateTxbyUtxo(baseUtxos, otherUtxos)
-// if err != nil {
-// return nil, err
-// }
-
-// return txs, nil
-// }
-
-// func SetUtxoView(db dbm.DB, view *state.UtxoViewpoint) error {
-// batch := db.NewBatch()
-// if err := database.SaveUtxoView(batch, view); err != nil {
-// return err
-// }
-// batch.Write()
-// return nil
-// }
-
-// //-------------------------Mock actual transaction----------------------------------
-// func MockTxsP2PKH(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
-// accountManager := account.NewManager(testDB, nil)
-// hsm, err := pseudohsm.New(keyDirPath)
-// if err != nil {
-// return nil, err
-// }
-
-// xpub, _, err := hsm.XCreate("TestP2PKH", "password", "en")
-// if err != nil {
-// return nil, err
-// }
-
-// txs := []*types.Tx{}
-// for i := 0; i < txNumber; i++ {
-// testAccountAlias := fmt.Sprintf("testAccount%d", i)
-// testAccount, err := accountManager.Create([]chainkd.XPub{xpub.XPub}, 1, testAccountAlias, signers.BIP0044)
-// if err != nil {
-// return nil, err
-// }
-
-// controlProg, err := accountManager.CreateAddress(testAccount.ID, false)
-// if err != nil {
-// return nil, err
-// }
-
-// utxo := MockSimpleUtxo(0, consensus.BTMAssetID, 1000000000, controlProg)
-// otherUtxos := GenerateOtherUtxos(i, otherAssetNum, 6000, controlProg)
-// tpl, err := BuildTx(utxo, otherUtxos, testAccount.Signer)
-// if err != nil {
-// return nil, err
-// }
-
-// if _, err := MockSign(tpl, hsm, "password"); err != nil {
-// return nil, err
-// }
-
-// txs = append(txs, tpl.Transaction)
-// }
-
-// return txs, nil
-// }
-
-// func MockTxsP2SH(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
-// accountManager := account.NewManager(testDB, nil)
-// hsm, err := pseudohsm.New(keyDirPath)
-// if err != nil {
-// return nil, err
-// }
-
-// xpub1, _, err := hsm.XCreate("TestP2SH1", "password", "en")
-// if err != nil {
-// return nil, err
-// }
-
-// xpub2, _, err := hsm.XCreate("TestP2SH2", "password", "en")
-// if err != nil {
-// return nil, err
-// }
-
-// txs := []*types.Tx{}
-// for i := 0; i < txNumber; i++ {
-// testAccountAlias := fmt.Sprintf("testAccount%d", i)
-// testAccount, err := accountManager.Create([]chainkd.XPub{xpub1.XPub, xpub2.XPub}, 2, testAccountAlias, signers.BIP0044)
-// if err != nil {
-// return nil, err
-// }
-
-// controlProg, err := accountManager.CreateAddress(testAccount.ID, false)
-// if err != nil {
-// return nil, err
-// }
-
-// utxo := MockSimpleUtxo(0, consensus.BTMAssetID, 1000000000, controlProg)
-// otherUtxos := GenerateOtherUtxos(i, otherAssetNum, 6000, controlProg)
-// tpl, err := BuildTx(utxo, otherUtxos, testAccount.Signer)
-// if err != nil {
-// return nil, err
-// }
-
-// if _, err := MockSign(tpl, hsm, "password"); err != nil {
-// return nil, err
-// }
-
-// txs = append(txs, tpl.Transaction)
-// }
-
-// return txs, nil
-// }
-
-// func MockTxsMultiSign(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
-// accountManager := account.NewManager(testDB, nil)
-// hsm, err := pseudohsm.New(keyDirPath)
-// if err != nil {
-// return nil, err
-// }
-
-// xpub1, _, err := hsm.XCreate("TestMultilNodeSign1", "password1", "en")
-// if err != nil {
-// return nil, err
-// }
-
-// xpub2, _, err := hsm.XCreate("TestMultilNodeSign2", "password2", "en")
-// if err != nil {
-// return nil, err
-// }
-// txs := []*types.Tx{}
-// for i := 0; i < txNumber; i++ {
-// testAccountAlias := fmt.Sprintf("testAccount%d", i)
-// testAccount, err := accountManager.Create([]chainkd.XPub{xpub1.XPub, xpub2.XPub}, 2, testAccountAlias, signers.BIP0044)
-// if err != nil {
-// return nil, err
-// }
-
-// controlProg, err := accountManager.CreateAddress(testAccount.ID, false)
-// if err != nil {
-// return nil, err
-// }
-
-// utxo := MockSimpleUtxo(0, consensus.BTMAssetID, 1000000000, controlProg)
-// otherUtxos := GenerateOtherUtxos(i, otherAssetNum, 6000, controlProg)
-// tpl, err := BuildTx(utxo, otherUtxos, testAccount.Signer)
-// if err != nil {
-// return nil, err
-// }
-
-// if _, err := MockSign(tpl, hsm, "password1"); err != nil {
-// return nil, err
-// }
-
-// if _, err := MockSign(tpl, hsm, "password2"); err != nil {
-// return nil, err
-// }
-
-// txs = append(txs, tpl.Transaction)
-// }
-
-// return txs, nil
-// }
+//
+//import (
+// "fmt"
+// "io/ioutil"
+// "os"
+// "testing"
+// "time"
+//
+// "github.com/bytom/bytom/account"
+// "github.com/bytom/bytom/blockchain/pseudohsm"
+// "github.com/bytom/bytom/blockchain/signers"
+// "github.com/bytom/bytom/blockchain/txbuilder"
+// "github.com/bytom/bytom/consensus"
+// "github.com/bytom/bytom/crypto/ed25519/chainkd"
+// "github.com/bytom/bytom/database"
+// dbm "github.com/bytom/bytom/database/leveldb"
+// "github.com/bytom/bytom/database/storage"
+// "github.com/bytom/bytom/event"
+// "github.com/bytom/bytom/mining"
+// "github.com/bytom/bytom/protocol"
+// "github.com/bytom/bytom/protocol/bc"
+// "github.com/bytom/bytom/protocol/bc/types"
+// "github.com/bytom/bytom/protocol/state"
+//)
+//
+//func BenchmarkChain_CoinBaseTx_NoAsset(b *testing.B) {
+// benchInsertChain(b, 0, 0, "")
+//}
+//
+//func BenchmarkChain_BtmTx_NoAsset_BASE(b *testing.B) {
+// benchInsertChain(b, 1, 0, "")
+//}
+//
+//func BenchmarkChain_5000BtmTx_NoAsset_BASE(b *testing.B) {
+// benchInsertChain(b, 5000, 0, "")
+//}
+//
+//func BenchmarkChain_5000BtmTx_1Asset_BASE(b *testing.B) {
+// benchInsertChain(b, 5000, 1, "")
+//}
+//
+//// standard Transaction
+//func BenchmarkChain_BtmTx_NoAsset_P2PKH(b *testing.B) {
+// benchInsertChain(b, 1000, 0, "P2PKH")
+//}
+//
+//func BenchmarkChain_BtmTx_1Asset_P2PKH(b *testing.B) {
+// benchInsertChain(b, 1000, 1, "P2PKH")
+//}
+//
+//func BenchmarkChain_BtmTx_NoAsset_P2SH(b *testing.B) {
+// benchInsertChain(b, 100, 0, "P2SH")
+//}
+//
+//func BenchmarkChain_BtmTx_1Asset_P2SH(b *testing.B) {
+// benchInsertChain(b, 100, 1, "P2SH")
+//}
+//
+//func BenchmarkChain_BtmTx_NoAsset_MultiSign(b *testing.B) {
+// benchInsertChain(b, 100, 0, "MultiSign")
+//}
+//
+//func BenchmarkChain_BtmTx_1Asset_MultiSign(b *testing.B) {
+// benchInsertChain(b, 100, 1, "MultiSign")
+//}
+//
+//func benchInsertChain(b *testing.B, blockTxNumber int, otherAssetNum int, txType string) {
+// b.StopTimer()
+// testNumber := b.N
+// totalTxNumber := testNumber * blockTxNumber
+//
+// dirPath, err := ioutil.TempDir(".", "testDB")
+// if err != nil {
+// b.Fatal("create dirPath err:", err)
+// }
+// defer os.RemoveAll(dirPath)
+//
+// testDB := dbm.NewDB("testdb", "leveldb", dirPath)
+// defer testDB.Close()
+//
+// // Generate a chain test data.
+// chain, txs, txPool, err := GenerateChainData(dirPath, testDB, totalTxNumber, otherAssetNum, txType)
+// if err != nil {
+// b.Fatal("GenerateChainData err:", err)
+// }
+//
+// b.ReportAllocs()
+// b.StartTimer()
+//
+// for i := 0; i < b.N; i++ {
+// testTxs := txs[blockTxNumber*i : blockTxNumber*(i+1)]
+// if err := InsertChain(chain, txPool, testTxs); err != nil {
+// b.Fatal("Failed to insert block into chain:", err)
+// }
+// }
+//}
+//
+//func GenerateChainData(dirPath string, testDB dbm.DB, txNumber, otherAssetNum int, txType string) (*protocol.Chain, []*types.Tx, *protocol.TxPool, error) {
+// var err error
+//
+// // generate transactions
+// txs := []*types.Tx{}
+// switch txType {
+// case "P2PKH":
+// txs, err = MockTxsP2PKH(dirPath, testDB, txNumber, otherAssetNum)
+// if err != nil {
+// return nil, nil, nil, err
+// }
+// case "P2SH":
+// txs, err = MockTxsP2SH(dirPath, testDB, txNumber, otherAssetNum)
+// if err != nil {
+// return nil, nil, nil, err
+// }
+// case "MultiSign":
+// txs, err = MockTxsMultiSign(dirPath, testDB, txNumber, otherAssetNum)
+// if err != nil {
+// return nil, nil, nil, err
+// }
+// default:
+// txs, err = CreateTxbyNum(txNumber, otherAssetNum)
+// if err != nil {
+// return nil, nil, nil, err
+// }
+// }
+//
+// // init UtxoViewpoint
+// utxoView := state.NewUtxoViewpoint()
+// utxoEntry := storage.NewUtxoEntry(false, 1, false)
+// for _, tx := range txs {
+// for _, id := range tx.SpentOutputIDs {
+// utxoView.Entries[id] = utxoEntry
+// }
+// }
+//
+// if err := SetUtxoView(testDB, utxoView); err != nil {
+// return nil, nil, nil, err
+// }
+//
+// store := database.NewStore(testDB)
+// dispatcher := event.NewDispatcher()
+// txPool := protocol.NewTxPool(store, dispatcher)
+// chain, err := protocol.NewChain(store, txPool)
+// if err != nil {
+// return nil, nil, nil, err
+// }
+//
+// go processNewTxch(txPool)
+//
+// return chain, txs, txPool, nil
+//}
+//
+//func InsertChain(chain *protocol.Chain, txPool *protocol.TxPool, txs []*types.Tx) error {
+// for _, tx := range txs {
+// if err := txbuilder.FinalizeTx(nil, chain, tx); err != nil {
+// return err
+// }
+// }
+// // imitate block broadcast deplay
+// time.Sleep(time.Second)
+// block, err := mining.NewBlockTemplate(chain, txPool, nil)
+// if err != nil {
+// return err
+// }
+// blockSize, err := block.MarshalText()
+// if err != nil {
+// return err
+// }
+// fmt.Println("blocksize:", uint64(len(blockSize)))
+// fmt.Println("block tx count:", uint64(len(block.Transactions)))
+// fmt.Println("coinbase txsize:", uint64(block.Transactions[0].SerializedSize))
+// if len(block.Transactions) > 1 {
+// fmt.Println("txsize:", uint64(block.Transactions[1].SerializedSize))
+// }
+// if _, err := chain.ProcessBlock(block); err != nil {
+// return err
+// }
+//
+// return nil
+//}
+//
+//func processNewTxch(txPool *protocol.TxPool) {
+//}
+//
+//func MockSimpleUtxo(index uint64, assetID *bc.AssetID, amount uint64, ctrlProg *account.CtrlProgram) *account.UTXO {
+// if ctrlProg == nil {
+// ctrlProg = &account.CtrlProgram{
+// AccountID: "",
+// Address: "",
+// KeyIndex: uint64(0),
+// ControlProgram: []byte{81},
+// Change: false,
+// }
+// }
+//
+// utxo := &account.UTXO{
+// OutputID: bc.Hash{V0: 1},
+// SourceID: bc.Hash{V0: 1},
+// AssetID: *assetID,
+// Amount: amount,
+// SourcePos: index,
+// ControlProgram: ctrlProg.ControlProgram,
+// ControlProgramIndex: ctrlProg.KeyIndex,
+// AccountID: ctrlProg.AccountID,
+// Address: ctrlProg.Address,
+// ValidHeight: 0,
+// }
+//
+// return utxo
+//}
+//
+//func GenerateBaseUtxos(num int, amount uint64, ctrlProg *account.CtrlProgram) []*account.UTXO {
+// utxos := []*account.UTXO{}
+// for i := 0; i < num; i++ {
+// utxo := MockSimpleUtxo(uint64(i), consensus.BTMAssetID, amount, ctrlProg)
+// utxos = append(utxos, utxo)
+// }
+//
+// return utxos
+//}
+//
+//func GenerateOtherUtxos(typeCount, num int, amount uint64, ctrlProg *account.CtrlProgram) []*account.UTXO {
+// utxos := []*account.UTXO{}
+//
+// assetID := &bc.AssetID{
+// V0: uint64(typeCount),
+// V1: uint64(1),
+// V2: uint64(0),
+// V3: uint64(1),
+// }
+//
+// for i := 0; i < num; i++ {
+// utxo := MockSimpleUtxo(uint64(typeCount*num+i), assetID, amount, ctrlProg)
+// utxos = append(utxos, utxo)
+// }
+//
+// return utxos
+//}
+//
+//func AddTxInputFromUtxo(utxo *account.UTXO, singer *signers.Signer) (*types.TxInput, *txbuilder.SigningInstruction, error) {
+// txInput, signInst, err := account.UtxoToInputs(singer, utxo)
+// if err != nil {
+// return nil, nil, err
+// }
+//
+// return txInput, signInst, nil
+//}
+//
+//func AddTxOutput(assetID bc.AssetID, amount uint64, controlProgram []byte) *types.TxOutput {
+// out := types.NewTxOutput(assetID, amount, controlProgram)
+// return out
+//}
+//
+//func CreateTxBuilder(baseUtxo *account.UTXO, btmServiceFlag bool, signer *signers.Signer) (*txbuilder.TemplateBuilder, error) {
+// tplBuilder := txbuilder.NewBuilder(time.Now())
+//
+// // add input
+// txInput, signInst, err := AddTxInputFromUtxo(baseUtxo, signer)
+// if err != nil {
+// return nil, err
+// }
+// tplBuilder.AddInput(txInput, signInst)
+//
+// // if the btm is the service charge, didn't need to add the output
+// if btmServiceFlag {
+// txOutput := AddTxOutput(baseUtxo.AssetID, 100, baseUtxo.ControlProgram)
+// tplBuilder.AddOutput(txOutput)
+// }
+//
+// return tplBuilder, nil
+//}
+//
+//func AddTxBuilder(tplBuilder *txbuilder.TemplateBuilder, utxo *account.UTXO, signer *signers.Signer) error {
+// txInput, signInst, err := AddTxInputFromUtxo(utxo, signer)
+// if err != nil {
+// return err
+// }
+// tplBuilder.AddInput(txInput, signInst)
+//
+// txOutput := AddTxOutput(utxo.AssetID, utxo.Amount, utxo.ControlProgram)
+// tplBuilder.AddOutput(txOutput)
+//
+// return nil
+//}
+//
+//func BuildTx(baseUtxo *account.UTXO, otherUtxos []*account.UTXO, signer *signers.Signer) (*txbuilder.Template, error) {
+// btmServiceFlag := false
+// if otherUtxos == nil || len(otherUtxos) == 0 {
+// btmServiceFlag = true
+// }
+//
+// tplBuilder, err := CreateTxBuilder(baseUtxo, btmServiceFlag, signer)
+// if err != nil {
+// return nil, err
+// }
+//
+// for _, u := range otherUtxos {
+// if err := AddTxBuilder(tplBuilder, u, signer); err != nil {
+// return nil, err
+// }
+// }
+//
+// tpl, _, err := tplBuilder.Build()
+// if err != nil {
+// return nil, err
+// }
+//
+// return tpl, nil
+//}
+//
+//func GenetrateTxbyUtxo(baseUtxo []*account.UTXO, otherUtxo [][]*account.UTXO) ([]*types.Tx, error) {
+// tmpUtxo := []*account.UTXO{}
+// txs := []*types.Tx{}
+// otherUtxoFlag := true
+//
+// if len(otherUtxo) == 0 || len(otherUtxo) != len(baseUtxo) {
+// otherUtxoFlag = false
+// }
+//
+// for i := 0; i < len(baseUtxo); i++ {
+// if otherUtxoFlag {
+// tmpUtxo = otherUtxo[i]
+// } else {
+// tmpUtxo = nil
+// }
+//
+// tpl, err := BuildTx(baseUtxo[i], tmpUtxo, nil)
+// if err != nil {
+// return nil, err
+// }
+//
+// txs = append(txs, tpl.Transaction)
+// }
+//
+// return txs, nil
+//}
+//
+//func CreateTxbyNum(txNumber, otherAssetNum int) ([]*types.Tx, error) {
+// baseUtxos := GenerateBaseUtxos(txNumber, 1000000000, nil)
+// otherUtxos := make([][]*account.UTXO, 0, txNumber)
+// if otherAssetNum != 0 {
+// for i := 0; i < txNumber; i++ {
+// utxos := GenerateOtherUtxos(i, otherAssetNum, 6000, nil)
+// otherUtxos = append(otherUtxos, utxos)
+// }
+// }
+//
+// txs, err := GenetrateTxbyUtxo(baseUtxos, otherUtxos)
+// if err != nil {
+// return nil, err
+// }
+//
+// return txs, nil
+//}
+//
+//func SetUtxoView(db dbm.DB, view *state.UtxoViewpoint) error {
+// batch := db.NewBatch()
+// if err := database.SaveUtxoView(batch, view); err != nil {
+// return err
+// }
+// batch.Write()
+// return nil
+//}
+//
+////-------------------------Mock actual transaction----------------------------------
+//func MockTxsP2PKH(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
+// accountManager := account.NewManager(testDB, nil)
+// hsm, err := pseudohsm.New(keyDirPath)
+// if err != nil {
+// return nil, err
+// }
+//
+// xpub, _, err := hsm.XCreate("TestP2PKH", "password", "en")
+// if err != nil {
+// return nil, err
+// }
+//
+// txs := []*types.Tx{}
+// for i := 0; i < txNumber; i++ {
+// testAccountAlias := fmt.Sprintf("testAccount%d", i)
+// testAccount, err := accountManager.Create([]chainkd.XPub{xpub.XPub}, 1, testAccountAlias, signers.BIP0044)
+// if err != nil {
+// return nil, err
+// }
+//
+// controlProg, err := accountManager.CreateAddress(testAccount.ID, false)
+// if err != nil {
+// return nil, err
+// }
+//
+// utxo := MockSimpleUtxo(0, consensus.BTMAssetID, 1000000000, controlProg)
+// otherUtxos := GenerateOtherUtxos(i, otherAssetNum, 6000, controlProg)
+// tpl, err := BuildTx(utxo, otherUtxos, testAccount.Signer)
+// if err != nil {
+// return nil, err
+// }
+//
+// if _, err := MockSign(tpl, hsm, "password"); err != nil {
+// return nil, err
+// }
+//
+// txs = append(txs, tpl.Transaction)
+// }
+//
+// return txs, nil
+//}
+//
+//func MockTxsP2SH(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
+// accountManager := account.NewManager(testDB, nil)
+// hsm, err := pseudohsm.New(keyDirPath)
+// if err != nil {
+// return nil, err
+// }
+//
+// xpub1, _, err := hsm.XCreate("TestP2SH1", "password", "en")
+// if err != nil {
+// return nil, err
+// }
+//
+// xpub2, _, err := hsm.XCreate("TestP2SH2", "password", "en")
+// if err != nil {
+// return nil, err
+// }
+//
+// txs := []*types.Tx{}
+// for i := 0; i < txNumber; i++ {
+// testAccountAlias := fmt.Sprintf("testAccount%d", i)
+// testAccount, err := accountManager.Create([]chainkd.XPub{xpub1.XPub, xpub2.XPub}, 2, testAccountAlias, signers.BIP0044)
+// if err != nil {
+// return nil, err
+// }
+//
+// controlProg, err := accountManager.CreateAddress(testAccount.ID, false)
+// if err != nil {
+// return nil, err
+// }
+//
+// utxo := MockSimpleUtxo(0, consensus.BTMAssetID, 1000000000, controlProg)
+// otherUtxos := GenerateOtherUtxos(i, otherAssetNum, 6000, controlProg)
+// tpl, err := BuildTx(utxo, otherUtxos, testAccount.Signer)
+// if err != nil {
+// return nil, err
+// }
+//
+// if _, err := MockSign(tpl, hsm, "password"); err != nil {
+// return nil, err
+// }
+//
+// txs = append(txs, tpl.Transaction)
+// }
+//
+// return txs, nil
+//}
+//
+//func MockTxsMultiSign(keyDirPath string, testDB dbm.DB, txNumber, otherAssetNum int) ([]*types.Tx, error) {
+// accountManager := account.NewManager(testDB, nil)
+// hsm, err := pseudohsm.New(keyDirPath)
+// if err != nil {
+// return nil, err
+// }
+//
+// xpub1, _, err := hsm.XCreate("TestMultilNodeSign1", "password1", "en")
+// if err != nil {
+// return nil, err
+// }
+//
+// xpub2, _, err := hsm.XCreate("TestMultilNodeSign2", "password2", "en")
+// if err != nil {
+// return nil, err
+// }
+// txs := []*types.Tx{}
+// for i := 0; i < txNumber; i++ {
+// testAccountAlias := fmt.Sprintf("testAccount%d", i)
+// testAccount, err := accountManager.Create([]chainkd.XPub{xpub1.XPub, xpub2.XPub}, 2, testAccountAlias, signers.BIP0044)
+// if err != nil {
+// return nil, err
+// }
+//
+// controlProg, err := accountManager.CreateAddress(testAccount.ID, false)
+// if err != nil {
+// return nil, err
+// }
+//
+// utxo := MockSimpleUtxo(0, consensus.BTMAssetID, 1000000000, controlProg)
+// otherUtxos := GenerateOtherUtxos(i, otherAssetNum, 6000, controlProg)
+// tpl, err := BuildTx(utxo, otherUtxos, testAccount.Signer)
+// if err != nil {
+// return nil, err
+// }
+//
+// if _, err := MockSign(tpl, hsm, "password1"); err != nil {
+// return nil, err
+// }
+//
+// if _, err := MockSign(tpl, hsm, "password2"); err != nil {
+// return nil, err
+// }
+//
+// txs = append(txs, tpl.Transaction)
+// }
+//
+// return txs, nil
+//}
if err != nil {
return err
}
- if err := SolveAndUpdate(chain, block); err != nil {
+ if _, err := chain.ProcessBlock(block); err != nil {
return err
}
}
return nil
}
-
-// SolveAndUpdate solve difficulty and update chain status
-func SolveAndUpdate(chain *protocol.Chain, block *types.Block) error {
- seed, err := chain.CalcNextSeed(&block.PreviousBlockHash)
- if err != nil {
- return err
- }
- Solve(seed, block)
- _, err = chain.ProcessBlock(block)
- return err
-}
-
-// Solve simulate solve difficulty by add result to cache
-func Solve(seed *bc.Hash, block *types.Block) {
- // hash := block.BlockHeader.Hash()
- // tensority.AIHash.AddCache(&hash, seed, &bc.Hash{})
-}
"github.com/bytom/bytom/blockchain/txbuilder"
"github.com/bytom/bytom/consensus"
"github.com/bytom/bytom/database"
+ dbm "github.com/bytom/bytom/database/leveldb"
"github.com/bytom/bytom/database/storage"
"github.com/bytom/bytom/protocol"
"github.com/bytom/bytom/protocol/bc"
"github.com/bytom/bytom/protocol/bc/types"
"github.com/bytom/bytom/protocol/vm"
"github.com/golang/protobuf/proto"
- dbm "github.com/bytom/bytom/database/leveldb"
)
const utxoPrefix = "UT:"
if err != nil {
return err
}
- err = SolveAndUpdate(ctx.Chain, block)
+ _, err = ctx.Chain.ProcessBlock(block)
if err != nil && blk.Invalid {
continue
}
}
}
}
+
return false
}
import (
"testing"
-
"time"
"github.com/bytom/bytom/config"
func init() {
consensus.ActiveNetParams = consensus.SoloNetParams
+ // height => block
blockMap = map[int][]*attachBlock{
0: {
{
Height: 1,
Version: 1,
Timestamp: 1556431597,
- Nonce: 5,
- PreviousBlockHash: testutil.MustDecodeHash("ce4fe9431cd0225b3a811f8f8ec922f2b07a921bb12a8dddae9a85540072c770"),
+ PreviousBlockHash: testutil.MustDecodeHash("cd7eaf7ea23d7099b2ff3968cf2f54850d7673c3e1519dc205e986421c7738a6"),
},
Transactions: []*types.Tx{
types.NewTx(types.TxData{
Height: 1,
Version: 1,
Timestamp: 1556431697,
- Nonce: 36,
- PreviousBlockHash: testutil.MustDecodeHash("ce4fe9431cd0225b3a811f8f8ec922f2b07a921bb12a8dddae9a85540072c770"),
+ PreviousBlockHash: testutil.MustDecodeHash("cd7eaf7ea23d7099b2ff3968cf2f54850d7673c3e1519dc205e986421c7738a6"),
},
Transactions: []*types.Tx{
types.NewTx(types.TxData{
},
2: {
// only has coinbase transaction
+ // the previous block blockMap[1][0]
{
block: &types.Block{
BlockHeader: types.BlockHeader{
Height: 2,
Version: 1,
Timestamp: 1556431604,
- Nonce: 0,
- PreviousBlockHash: testutil.MustDecodeHash("2eaf7f40b0a0d4a5025f3d5d9b8589d3db1634f7b55089ca59253a9c587266b2"),
+ PreviousBlockHash: testutil.MustDecodeHash("4691aff4f2f6d9bb0d19c85933b6c8101dfecf43b2b000714ad2066cac843fd7"),
},
Transactions: []*types.Tx{
types.NewTx(types.TxData{
verifyResult: []*bc.TxVerifyResult{{StatusFail: false}},
},
// with spend btm transaction
+ // the previous block blockMap[1][0]
{
block: &types.Block{
BlockHeader: types.BlockHeader{
Height: 2,
Version: 1,
Timestamp: 1556431604,
- Nonce: 12,
- PreviousBlockHash: testutil.MustDecodeHash("2eaf7f40b0a0d4a5025f3d5d9b8589d3db1634f7b55089ca59253a9c587266b2"),
+ PreviousBlockHash: testutil.MustDecodeHash("4691aff4f2f6d9bb0d19c85933b6c8101dfecf43b2b000714ad2066cac843fd7"),
},
Transactions: []*types.Tx{
types.NewTx(types.TxData{
verifyResult: []*bc.TxVerifyResult{{StatusFail: false}, {StatusFail: false}},
},
// with btm retire transaction
+ // the previous block blockMap[1][0]
{
block: &types.Block{
BlockHeader: types.BlockHeader{
Height: 2,
Version: 1,
Timestamp: 1556431607,
- Nonce: 4,
- PreviousBlockHash: testutil.MustDecodeHash("2eaf7f40b0a0d4a5025f3d5d9b8589d3db1634f7b55089ca59253a9c587266b2"),
+ PreviousBlockHash: testutil.MustDecodeHash("4691aff4f2f6d9bb0d19c85933b6c8101dfecf43b2b000714ad2066cac843fd7"),
},
Transactions: []*types.Tx{
types.NewTx(types.TxData{
verifyResult: []*bc.TxVerifyResult{{StatusFail: false}, {StatusFail: false}},
},
// with issuance transaction
+ // the previous block blockMap[1][0]
{
block: &types.Block{
BlockHeader: types.BlockHeader{
Height: 2,
Version: 1,
Timestamp: 1556431607,
- Nonce: 17,
- PreviousBlockHash: testutil.MustDecodeHash("2eaf7f40b0a0d4a5025f3d5d9b8589d3db1634f7b55089ca59253a9c587266b2"),
+ PreviousBlockHash: testutil.MustDecodeHash("4691aff4f2f6d9bb0d19c85933b6c8101dfecf43b2b000714ad2066cac843fd7"),
},
Transactions: []*types.Tx{
types.NewTx(types.TxData{
verifyResult: []*bc.TxVerifyResult{{StatusFail: false}, {StatusFail: false}},
},
// with issuance transaction but status fail is true
+ // the previous block blockMap[1][0]
{
block: &types.Block{
BlockHeader: types.BlockHeader{
Height: 2,
Version: 1,
Timestamp: 1556431607,
- Nonce: 4,
- PreviousBlockHash: testutil.MustDecodeHash("2eaf7f40b0a0d4a5025f3d5d9b8589d3db1634f7b55089ca59253a9c587266b2"),
+ PreviousBlockHash: testutil.MustDecodeHash("4691aff4f2f6d9bb0d19c85933b6c8101dfecf43b2b000714ad2066cac843fd7"),
},
Transactions: []*types.Tx{
types.NewTx(types.TxData{
verifyResult: []*bc.TxVerifyResult{{StatusFail: false}, {StatusFail: true}},
},
// with non btm transaction
+ // the previous block blockMap[1][0]
{
block: &types.Block{
BlockHeader: types.BlockHeader{
Height: 2,
Version: 1,
Timestamp: 1556431607,
- Nonce: 4,
- PreviousBlockHash: testutil.MustDecodeHash("2eaf7f40b0a0d4a5025f3d5d9b8589d3db1634f7b55089ca59253a9c587266b2"),
+ PreviousBlockHash: testutil.MustDecodeHash("4691aff4f2f6d9bb0d19c85933b6c8101dfecf43b2b000714ad2066cac843fd7"),
},
Transactions: []*types.Tx{
types.NewTx(types.TxData{
verifyResult: []*bc.TxVerifyResult{{StatusFail: false}, {StatusFail: false}},
},
// with non btm transaction but status fail is true
+ // the previous block blockMap[1][0]
{
block: &types.Block{
BlockHeader: types.BlockHeader{
Height: 2,
Version: 1,
Timestamp: 1556431607,
- Nonce: 12,
- PreviousBlockHash: testutil.MustDecodeHash("2eaf7f40b0a0d4a5025f3d5d9b8589d3db1634f7b55089ca59253a9c587266b2"),
+ PreviousBlockHash: testutil.MustDecodeHash("4691aff4f2f6d9bb0d19c85933b6c8101dfecf43b2b000714ad2066cac843fd7"),
},
Transactions: []*types.Tx{
types.NewTx(types.TxData{
Height: 3,
Version: 1,
Timestamp: 1556431640,
- Nonce: 0,
- PreviousBlockHash: testutil.MustDecodeHash("09c6064f4f1e7325440c45df03e97f97dbfbb66033315a384308256038af6c30"),
+ PreviousBlockHash: testutil.MustDecodeHash("e8d37fd75137d6e634cacb1656f780fab967ae4c1c98fa26a215a878d48e5ab0"),
},
Transactions: []*types.Tx{
types.NewTx(types.TxData{
Height: 3,
Version: 1,
Timestamp: 1556431640,
- Nonce: 5,
- PreviousBlockHash: testutil.MustDecodeHash("33f56264283cc12e3b232068caa13c1fd052c21b231a94e8c0a40bac25629f88"),
+ PreviousBlockHash: testutil.MustDecodeHash("24f2c89193fc750d325145da1f0c574cceadef09751095220039c91836357d6e"),
},
Transactions: []*types.Tx{
types.NewTx(types.TxData{
import (
"fmt"
+ dbm "github.com/bytom/bytom/database/leveldb"
"github.com/bytom/bytom/protocol"
"github.com/bytom/bytom/protocol/bc/types"
- dbm "github.com/bytom/bytom/database/leveldb"
)
func declChain(name string, baseChain *protocol.Chain, baseHeight uint64, height uint64) (*protocol.Chain, error) {
if err != nil {
return nil, err
}
- if err := SolveAndUpdate(chain, block); err != nil {
+ if _, err := chain.ProcessBlock(block); err != nil {
return nil, err
}
}
Height: header.Height,
PreviousBlockHash: *header.PreviousBlockId,
Timestamp: header.Timestamp,
- Nonce: header.Nonce,
}
return &state.BlockNode{
Parent: nil,
Version: h.Version,
Height: h.Height,
Timestamp: h.Timestamp,
- Nonce: h.Nonce,
}
}
Height: 100,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block0"),
Height: 101,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block1"),
Height: 102,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block2"),
Height: 102,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block3"),
Height: 103,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block4"),
Height: 104,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block5"),
Height: 105,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block6"),
Height: 106,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block7"),
Height: 107,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block8"),
Height: 108,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block9"),
Height: 105,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block10"),
Height: 105,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block11"),
Height: 106,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block12"),
Height: 107,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block13"),
Height: 106,
PreviousBlockHash: testutil.MustDecodeHash("0ab29c0bd7bff3b3b7eb98802f8d5f8833884c86c0fb21559a65cc58dda99667"),
Timestamp: 1522908275,
- Nonce: 0,
},
Transactions: []*types.Tx{
coinBaseTx(41250000000, "arbitrary block14"),
}
func (ctx *walletTestContext) update(block *types.Block) error {
- if err := SolveAndUpdate(ctx.Chain, block); err != nil {
+ if _, err := ctx.Chain.ProcessBlock(block); err != nil {
return err
}
if err := ctx.Wallet.AttachBlock(block); err != nil {