Skip to content

Commit

Permalink
don't store whole chain index element
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Nov 14, 2024
1 parent 7e5afd1 commit 8872732
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
14 changes: 7 additions & 7 deletions explorer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ type V2BlockData struct {
// A Block is a block containing wrapped transactions and siacoin
// outputs for the miner payouts.
type Block struct {
Height uint64 `json:"height"`
ParentID types.BlockID `json:"parentID"`
Nonce uint64 `json:"nonce"`
Timestamp time.Time `json:"timestamp"`
ChainIndexElement types.ChainIndexElement `json:"chainIndexElement"`
MinerPayouts []SiacoinOutput `json:"minerPayouts"`
Transactions []Transaction `json:"transactions"`
Height uint64 `json:"height"`
ParentID types.BlockID `json:"parentID"`
Nonce uint64 `json:"nonce"`
Timestamp time.Time `json:"timestamp"`
LeafIndex uint64 `json:"leafIndex"`
MinerPayouts []SiacoinOutput `json:"minerPayouts"`
Transactions []Transaction `json:"transactions"`

V2 *V2BlockData `json:"v2,omitempty"`
}
Expand Down
2 changes: 1 addition & 1 deletion persist/sqlite/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (s *Store) Block(id types.BlockID) (result explorer.Block, err error) {
err = s.transaction(func(tx *txn) error {
var v2Height uint64
var v2Commitment types.Hash256
err := tx.QueryRow(`SELECT parent_id, nonce, timestamp, height, chain_index_element, v2_height, v2_commitment FROM blocks WHERE id = ?`, encode(id)).Scan(decode(&result.ParentID), decode(&result.Nonce), decode(&result.Timestamp), &result.Height, decode(&result.ChainIndexElement), decodeNull(&v2Height), decodeNull(&v2Commitment))
err := tx.QueryRow(`SELECT parent_id, nonce, timestamp, height, leaf_index, v2_height, v2_commitment FROM blocks WHERE id = ?`, encode(id)).Scan(decode(&result.ParentID), decode(&result.Nonce), decode(&result.Timestamp), &result.Height, decode(&result.LeafIndex), decodeNull(&v2Height), decodeNull(&v2Commitment))
if err != nil {
return fmt.Errorf("failed to get block: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions persist/sqlite/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ func addBlock(tx *txn, b types.Block, cie types.ChainIndexElement, height uint64
v2Height = encode(b.V2.Height)
v2Commitment = encode(b.V2.Commitment)
}
cie.StateElement.MerkleProof = nil
_, err := tx.Exec("INSERT INTO blocks(id, height, parent_id, nonce, timestamp, chain_index_element, v2_height, v2_commitment) VALUES (?, ?, ?, ?, ?, ?, ?, ?);", encode(b.ID()), height, encode(b.ParentID), encode(b.Nonce), encode(b.Timestamp), encode(cie), v2Height, v2Commitment)
_, err := tx.Exec("INSERT INTO blocks(id, height, parent_id, nonce, timestamp, leaf_index, v2_height, v2_commitment) VALUES (?, ?, ?, ?, ?, ?, ?, ?);", encode(b.ID()), height, encode(b.ParentID), encode(b.Nonce), encode(b.Timestamp), encode(cie.StateElement.LeafIndex), v2Height, v2Commitment)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion persist/sqlite/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CREATE TABLE blocks (
parent_id BLOB NOT NULL,
nonce BLOB NOT NULL,
timestamp INTEGER NOT NULL,
chain_index_element BLOB NOT NULL,
leaf_index BLOB NOT NULL,

v2_height INTEGER,
v2_commitment BLOB
Expand Down
11 changes: 9 additions & 2 deletions persist/sqlite/v2consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,18 @@ func getCIE(t *testing.T, db explorer.Store, bid types.BlockID) types.ChainIndex
t.Fatal(err)
}

b.ChainIndexElement.StateElement.MerkleProof, err = db.MerkleProof(b.ChainIndexElement.StateElement.LeafIndex)
merkleProof, err := db.MerkleProof(b.LeafIndex)
if err != nil {
t.Fatal(err)
}
return b.ChainIndexElement
return types.ChainIndexElement{
ID: bid,
StateElement: types.StateElement{
LeafIndex: b.LeafIndex,
MerkleProof: merkleProof,
},
ChainIndex: types.ChainIndex{ID: bid, Height: b.Height},
}
}

func TestV2ArbitraryData(t *testing.T) {
Expand Down

0 comments on commit 8872732

Please sign in to comment.