Skip to content

Add Merkle Root on Spine Block #1222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions api/service/blockApiService_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func (*mockQueryExecutorGetBlocksSuccess) ExecuteSelect(qe string, tx bool, args
mockGoodBlock.GetTotalFee(),
mockGoodBlock.GetTotalCoinBase(),
mockGoodBlock.GetVersion(),
mockGoodBlock.GetMerkleRoot(),
mockGoodBlock.GetMerkleTree(),
mockGoodBlock.GetReferenceBlockHeight(),
).AddRow(
mockGoodBlock.GetHeight(),
mockGoodBlock.GetID(),
Expand All @@ -115,6 +118,9 @@ func (*mockQueryExecutorGetBlocksSuccess) ExecuteSelect(qe string, tx bool, args
mockGoodBlock.GetTotalFee(),
mockGoodBlock.GetTotalCoinBase(),
mockGoodBlock.GetVersion(),
mockGoodBlock.GetMerkleRoot(),
mockGoodBlock.GetMerkleTree(),
mockGoodBlock.GetReferenceBlockHeight(),
))
rows, _ := db.Query(qe)
return rows, nil
Expand Down Expand Up @@ -149,6 +155,9 @@ func (*mockQueryGetBlockByIDSuccess) ExecuteSelectRow(qStr string, tx bool, args
mockGoodBlock.GetTotalFee(),
mockGoodBlock.GetTotalCoinBase(),
mockGoodBlock.GetVersion(),
mockGoodBlock.GetMerkleRoot(),
mockGoodBlock.GetMerkleTree(),
mockGoodBlock.GetReferenceBlockHeight(),
))
return db.QueryRow(qStr), nil
}
Expand Down Expand Up @@ -259,6 +268,9 @@ func (*mockQueryGetBlockByHeightSuccess) ExecuteSelectRow(qStr string, tx bool,
mockGoodBlock.GetTotalFee(),
mockGoodBlock.GetTotalCoinBase(),
mockGoodBlock.GetVersion(),
mockGoodBlock.GetMerkleRoot(),
mockGoodBlock.GetMerkleTree(),
mockGoodBlock.GetReferenceBlockHeight(),
))
return db.QueryRow(qStr), nil
}
Expand Down Expand Up @@ -374,6 +386,9 @@ func (*mockQueryGetBlocksSuccess) ExecuteSelect(qStr string, tx bool, args ...in
mockGoodBlock.GetTotalFee(),
mockGoodBlock.GetTotalCoinBase(),
mockGoodBlock.GetVersion(),
mockGoodBlock.GetMerkleRoot(),
mockGoodBlock.GetMerkleTree(),
mockGoodBlock.GetReferenceBlockHeight(),
),
)
return db.Query(qStr)
Expand Down
1 change: 1 addition & 0 deletions cmd/genesisblock/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ func getGenesisBlockID(genesisEntries []genesisEntry) (mainBlockID, spineBlockID
nil,
nil,
nil,
bs,
)
spine, err := sb.GenerateGenesisBlock(genesisConfig)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions common/auth/nodeAuthValidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func (*mockExecutorValidateSuccess) ExecuteSelectRow(qStr string, tx bool, args
10000000,
1,
0,
[]byte{},
[]byte{},
0,
)
mock.ExpectQuery("SELECT").WillReturnRows(mockedRows)
return db.QueryRow(qStr), nil
Expand Down
7 changes: 4 additions & 3 deletions common/constant/smith.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ var (
Spinechain smithing
*/

SpineSmithingBlockCreationTime = int64(30)
SpineSmithingNetworkTolerance = int64(15)
SpineSmithingBlocksmithTimeGap = int64(10)
SpineSmithingBlockCreationTime = int64(30)
SpineSmithingNetworkTolerance = int64(15)
SpineSmithingBlocksmithTimeGap = int64(10)
SpineReferenceBlockHeightOffset = uint32(5)
)
24 changes: 24 additions & 0 deletions common/database/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,30 @@ func (m *Migration) Init() error {
`
CREATE INDEX "transaction_block_id_idx" ON "transaction" ("block_id")
`,
`
ALTER TABLE "main_block"
ADD COLUMN "merkle_root" BLOB AFTER "payload_hash"
`,
`
ALTER TABLE "main_block"
ADD COLUMN "merkle_tree" BLOB AFTER "merkle_root"
`,
`
ALTER TABLE "main_block"
ADD COLUMN "reference_block_height" INTEGER AFTER "merkle_tree"
`,
`
ALTER TABLE "spine_block"
ADD COLUMN "merkle_root" BLOB AFTER "payload_hash"
`,
`
ALTER TABLE "spine_block"
ADD COLUMN "merkle_tree" BLOB AFTER "merkle_root"
`,
`
ALTER TABLE "spine_block"
ADD COLUMN "reference_block_height" INTEGER AFTER "merkle_tree"
`,
}
return nil
}
Expand Down
151 changes: 89 additions & 62 deletions common/model/block.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions common/query/blockQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func NewBlockQuery(chaintype chaintype.ChainType) *BlockQuery {
"total_fee",
"total_coinbase",
"version",
"merkle_root",
"merkle_tree",
"reference_block_height",
},
TableName: "block",
ChainType: chaintype,
Expand Down Expand Up @@ -175,6 +178,9 @@ func (*BlockQuery) ExtractModel(block *model.Block) []interface{} {
block.TotalFee,
block.TotalCoinBase,
block.Version,
block.MerkleRoot,
block.MerkleTree,
block.ReferenceBlockHeight,
}
}

Expand All @@ -201,6 +207,9 @@ func (*BlockQuery) BuildModel(blocks []*model.Block, rows *sql.Rows) ([]*model.B
&block.TotalFee,
&block.TotalCoinBase,
&block.Version,
&block.MerkleRoot,
&block.MerkleTree,
&block.ReferenceBlockHeight,
)
if err != nil {
return nil, err
Expand All @@ -227,6 +236,9 @@ func (*BlockQuery) Scan(block *model.Block, row *sql.Row) error {
&block.TotalFee,
&block.TotalCoinBase,
&block.Version,
&block.MerkleRoot,
&block.MerkleTree,
&block.ReferenceBlockHeight,
)
if err != nil {
return err
Expand Down
Loading