-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update block headers to include multiple levels of parent blocks (#1822)
* Replace the old parents in the block header with BlockLevelParents. * Begin fixing compilation errors. * Implement database serialization for block level parents. * Implement p2p serialization for block level parents. * Implement rpc serialization for block level parents. * Add DirectParents() to the block header interface. * Use DirectParents() instead of Parents() in some places. * Revert test_block_builder.go. * Add block level parents to hash serialization. * Use the zero hash for genesis finality points. * Fix failing tests. * Fix a variable name. * Update headerEstimatedSerializedSize. * Add comments in blocklevelparents.go. * Fix the rpc-stability stability test. * Change the field number for `parents` fields in p2p.proto and rpc.proto. * Remove MsgBlockHeader::NumParentBlocks.
- Loading branch information
1 parent
ba5880f
commit 837dac6
Showing
40 changed files
with
2,615 additions
and
2,272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
domain/consensus/database/serialization/blocklevelparents.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package serialization | ||
|
||
import ( | ||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi" | ||
) | ||
|
||
// DbBlockLevelParentsToDomainBlockLevelParents converts a DbBlockLevelParents to a BlockLevelParents | ||
func DbBlockLevelParentsToDomainBlockLevelParents(dbBlockLevelParents *DbBlockLevelParents) (externalapi.BlockLevelParents, error) { | ||
domainBlockLevelParents := make(externalapi.BlockLevelParents, len(dbBlockLevelParents.ParentHashes)) | ||
for i, parentHash := range dbBlockLevelParents.ParentHashes { | ||
var err error | ||
domainBlockLevelParents[i], err = externalapi.NewDomainHashFromByteSlice(parentHash.Hash) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return domainBlockLevelParents, nil | ||
} | ||
|
||
// DomainBlockLevelParentsToDbBlockLevelParents converts a BlockLevelParents to a DbBlockLevelParents | ||
func DomainBlockLevelParentsToDbBlockLevelParents(domainBlockLevelParents externalapi.BlockLevelParents) *DbBlockLevelParents { | ||
parentHashes := make([]*DbHash, len(domainBlockLevelParents)) | ||
for i, parentHash := range domainBlockLevelParents { | ||
parentHashes[i] = &DbHash{Hash: parentHash.ByteSlice()} | ||
} | ||
return &DbBlockLevelParents{ParentHashes: parentHashes} | ||
} | ||
|
||
// DomainParentsToDbParents converts a slice of BlockLevelParents to a slice of DbBlockLevelParents | ||
func DomainParentsToDbParents(domainParents []externalapi.BlockLevelParents) []*DbBlockLevelParents { | ||
dbParents := make([]*DbBlockLevelParents, len(domainParents)) | ||
for i, domainBlockLevelParents := range domainParents { | ||
dbParents[i] = DomainBlockLevelParentsToDbBlockLevelParents(domainBlockLevelParents) | ||
} | ||
return dbParents | ||
} | ||
|
||
// DbParentsToDomainParents converts a slice of DbBlockLevelParents to a slice of BlockLevelParents | ||
func DbParentsToDomainParents(dbParents []*DbBlockLevelParents) ([]externalapi.BlockLevelParents, error) { | ||
domainParents := make([]externalapi.BlockLevelParents, len(dbParents)) | ||
for i, domainBlockLevelParents := range dbParents { | ||
var err error | ||
domainParents[i], err = DbBlockLevelParentsToDomainBlockLevelParents(domainBlockLevelParents) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return domainParents, nil | ||
} |
Oops, something went wrong.