mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +00:00
[NOD-1493] Implement types for serialization (#980)
* [NOD-1493] Add DbAcceptanceData. * [NOD-1493] Add DbBlockRelations. * [NOD-1493] Add DbBlockStatus. * [NOD-1493] Add DbBlockGhostdagData. * [NOD-1493] Add DbMultiset. * [NOD-1493] Add DbPruningPoint. * [NOD-1493] Add DbUtxoSet. * [NOD-1493] Add DbReachabilityData. * [NOD-1493] Add DbReachabilityReindexRoot. * [NOD-1493] Add DbUtxoDiff. * [NOD-1493] Add DbUtxoDiffChild. * [NOD-1493] Make sure everything is lowercase. * [NOD-1493] Add DbHash. * [NOD-1493] Fix BlockHeaderStore.
This commit is contained in:
parent
126e2e49bb
commit
9cf1557c37
File diff suppressed because it is too large
Load Diff
@ -10,38 +10,127 @@ message DbBlock {
|
|||||||
|
|
||||||
message DbBlockHeader {
|
message DbBlockHeader {
|
||||||
int32 version = 1;
|
int32 version = 1;
|
||||||
repeated bytes parentHashes = 2;
|
repeated DbHash parentHashes = 2;
|
||||||
bytes hashMerkleRoot = 3;
|
DbHash hashMerkleRoot = 3;
|
||||||
bytes acceptedIDMerkleRoot = 4;
|
DbHash acceptedIDMerkleRoot = 4;
|
||||||
bytes utxoCommitment = 5;
|
DbHash utxoCommitment = 5;
|
||||||
int64 timeInMilliseconds = 6;
|
int64 timeInMilliseconds = 6;
|
||||||
uint32 bits = 7;
|
uint32 bits = 7;
|
||||||
uint64 nonce = 8;
|
uint64 nonce = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message DbHash {
|
||||||
|
bytes hash = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message DbTransaction {
|
message DbTransaction {
|
||||||
int32 Version = 1;
|
int32 version = 1;
|
||||||
repeated DbTransactionInput Inputs = 2;
|
repeated DbTransactionInput inputs = 2;
|
||||||
repeated DbTransactionOutput Outputs = 3;
|
repeated DbTransactionOutput outputs = 3;
|
||||||
uint64 LockTime = 4;
|
uint64 lockTime = 4;
|
||||||
bytes SubnetworkID = 5;
|
DbSubnetworkId subnetworkID = 5;
|
||||||
uint64 Gas = 6;
|
uint64 gas = 6;
|
||||||
bytes PayloadHash = 7;
|
DbHash payloadHash = 7;
|
||||||
bytes Payload = 8;
|
DbHash payload = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DbTransactionInput {
|
message DbTransactionInput {
|
||||||
DbOutpoint PreviousOutpoint = 1;
|
DbOutpoint previousOutpoint = 1;
|
||||||
bytes SignatureScript = 2;
|
bytes signatureScript = 2;
|
||||||
uint64 Sequence = 3;
|
uint64 sequence = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DbOutpoint {
|
message DbOutpoint {
|
||||||
bytes TransactionID = 1;
|
DbTransactionId transactionID = 1;
|
||||||
uint32 Index = 2;
|
uint32 index = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbTransactionId {
|
||||||
|
bytes transactionId = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DbTransactionOutput {
|
message DbTransactionOutput {
|
||||||
uint64 Value = 1;
|
uint64 value = 1;
|
||||||
bytes ScriptPublicKey = 2;
|
bytes scriptPublicKey = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbSubnetworkId {
|
||||||
|
bytes subnetworkId = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbAcceptanceData {
|
||||||
|
repeated DbBlockAcceptanceData blockAcceptanceData = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbBlockAcceptanceData {
|
||||||
|
repeated DbTransactionAcceptanceData transactionAcceptanceData = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbTransactionAcceptanceData {
|
||||||
|
DbTransaction transaction = 1;
|
||||||
|
uint64 fee = 2;
|
||||||
|
bool isAccepted = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbBlockRelations {
|
||||||
|
repeated DbHash parents = 1;
|
||||||
|
repeated DbHash children = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbBlockStatus {
|
||||||
|
uint32 status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbBlockGhostdagData {
|
||||||
|
uint64 blueScore = 1;
|
||||||
|
DbHash selectedParent = 2;
|
||||||
|
repeated DbHash mergeSetBlues = 3;
|
||||||
|
repeated DbHash mergeSetReds = 4;
|
||||||
|
repeated DbBluesAnticoneSizes bluesAnticoneSizes = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbBluesAnticoneSizes {
|
||||||
|
DbHash blueHash = 1;
|
||||||
|
uint32 anticoneSize = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbMultiset {
|
||||||
|
bytes multiset = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbUtxoSet {
|
||||||
|
repeated DbUtxoCollectionItem items = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbUtxoCollectionItem {
|
||||||
|
DbOutpoint outpoint = 1;
|
||||||
|
DbUtxoEntry utxoEntry = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbUtxoEntry {
|
||||||
|
uint64 amount = 1;
|
||||||
|
bytes scriptPublicKey = 2;
|
||||||
|
uint64 blockBlueScore = 3;
|
||||||
|
bool isCoinbase = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbReachabilityData {
|
||||||
|
DbReachabilityTreeNode treeNode = 1;
|
||||||
|
repeated DbHash futureCoveringSet = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbReachabilityTreeNode {
|
||||||
|
repeated DbHash children = 1;
|
||||||
|
DbHash parent = 2;
|
||||||
|
DbReachabilityInterval interval = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbReachabilityInterval {
|
||||||
|
uint64 start = 1;
|
||||||
|
uint64 end = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DbUtxoDiff {
|
||||||
|
repeated DbUtxoCollectionItem toAdd = 1;
|
||||||
|
repeated DbUtxoCollectionItem toRemove = 2;
|
||||||
}
|
}
|
||||||
|
@ -107,17 +107,17 @@ func (bms *blockHeaderStore) hashAsKey(hash *externalapi.DomainHash) model.DBKey
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bms *blockHeaderStore) serializeHeader(header *externalapi.DomainBlockHeader) ([]byte, error) {
|
func (bms *blockHeaderStore) serializeHeader(header *externalapi.DomainBlockHeader) ([]byte, error) {
|
||||||
dbParentHashes := make([][]byte, len(header.ParentHashes))
|
dbParentHashes := make([]*serialization.DbHash, len(header.ParentHashes))
|
||||||
for i, parentHash := range header.ParentHashes {
|
for i, parentHash := range header.ParentHashes {
|
||||||
dbParentHashes[i] = parentHash[:]
|
dbParentHashes[i] = &serialization.DbHash{Hash: parentHash[:]}
|
||||||
}
|
}
|
||||||
|
|
||||||
dbBlockHeader := &serialization.DbBlockHeader{
|
dbBlockHeader := &serialization.DbBlockHeader{
|
||||||
Version: header.Version,
|
Version: header.Version,
|
||||||
ParentHashes: dbParentHashes,
|
ParentHashes: dbParentHashes,
|
||||||
HashMerkleRoot: header.HashMerkleRoot[:],
|
HashMerkleRoot: &serialization.DbHash{Hash: header.HashMerkleRoot[:]},
|
||||||
AcceptedIDMerkleRoot: header.AcceptedIDMerkleRoot[:],
|
AcceptedIDMerkleRoot: &serialization.DbHash{Hash: header.AcceptedIDMerkleRoot[:]},
|
||||||
UtxoCommitment: header.UTXOCommitment[:],
|
UtxoCommitment: &serialization.DbHash{Hash: header.UTXOCommitment[:]},
|
||||||
TimeInMilliseconds: header.TimeInMilliseconds,
|
TimeInMilliseconds: header.TimeInMilliseconds,
|
||||||
Bits: header.Bits,
|
Bits: header.Bits,
|
||||||
Nonce: header.Nonce,
|
Nonce: header.Nonce,
|
||||||
@ -135,20 +135,20 @@ func (bms *blockHeaderStore) deserializeHeader(headerBytes []byte) (*externalapi
|
|||||||
|
|
||||||
parentHashes := make([]*externalapi.DomainHash, len(dbBlockHeader.ParentHashes))
|
parentHashes := make([]*externalapi.DomainHash, len(dbBlockHeader.ParentHashes))
|
||||||
for i, dbParentHash := range dbBlockHeader.ParentHashes {
|
for i, dbParentHash := range dbBlockHeader.ParentHashes {
|
||||||
parentHashes[i], err = hashes.FromBytes(dbParentHash)
|
parentHashes[i], err = hashes.FromBytes(dbParentHash.Hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hashMerkleRoot, err := hashes.FromBytes(dbBlockHeader.HashMerkleRoot)
|
hashMerkleRoot, err := hashes.FromBytes(dbBlockHeader.HashMerkleRoot.Hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
acceptedIDMerkleRoot, err := hashes.FromBytes(dbBlockHeader.AcceptedIDMerkleRoot)
|
acceptedIDMerkleRoot, err := hashes.FromBytes(dbBlockHeader.AcceptedIDMerkleRoot.Hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
utxoCommitment, err := hashes.FromBytes(dbBlockHeader.UtxoCommitment)
|
utxoCommitment, err := hashes.FromBytes(dbBlockHeader.UtxoCommitment.Hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user