Skip to content
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
4 changes: 1 addition & 3 deletions vms/avm/block/executor/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,12 @@ func (b *Block) Accept(context.Context) error {
return err
}

txChecksum, utxoChecksum := b.manager.state.Checksums()
b.manager.backend.Ctx.Log.Trace(
"accepted block",
zap.Stringer("blkID", blkID),
zap.Uint64("height", b.Height()),
zap.Stringer("parentID", b.Parent()),
zap.Stringer("txChecksum", txChecksum),
zap.Stringer("utxoChecksum", utxoChecksum),
zap.Stringer("checksum", b.manager.state.Checksum()),
)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion vms/avm/block/executor/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ func TestBlockAccept(t *testing.T) {
// because we mock the call to shared memory
mockManagerState.EXPECT().CommitBatch().Return(nil, nil)
mockManagerState.EXPECT().Abort()
mockManagerState.EXPECT().Checksums().Return(ids.Empty, ids.Empty)
mockManagerState.EXPECT().Checksum().Return(ids.Empty)

mockSharedMemory := atomicmock.NewSharedMemory(ctrl)
mockSharedMemory.EXPECT().Apply(gomock.Any(), gomock.Any()).Return(nil)
Expand Down
49 changes: 6 additions & 43 deletions vms/avm/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ type State interface {
// pending changes to the base database.
CommitBatch() (database.Batch, error)

// Checksums returns the current TxChecksum and UTXOChecksum.
Checksums() (txChecksum ids.ID, utxoChecksum ids.ID)
// Checksum returns the current state checksum.
Checksum() ids.ID

Close() error
}
Expand Down Expand Up @@ -134,9 +134,6 @@ type state struct {
lastAccepted, persistedLastAccepted ids.ID
timestamp, persistedTimestamp time.Time
singletonDB database.Database

trackChecksum bool
txChecksum ids.ID
}

func New(
Expand Down Expand Up @@ -183,7 +180,7 @@ func New(
return nil, err
}

s := &state{
return &state{
parser: parser,
db: db,

Expand All @@ -204,10 +201,7 @@ func New(
blockDB: blockDB,

singletonDB: singletonDB,

trackChecksum: trackChecksums,
}
return s, s.initTxChecksum()
}, nil
}

func (s *state) GetUTXO(utxoID ids.ID) (*avax.UTXO, error) {
Expand Down Expand Up @@ -264,7 +258,6 @@ func (s *state) GetTx(txID ids.ID) (*txs.Tx, error) {

func (s *state) AddTx(tx *txs.Tx) {
txID := tx.ID()
s.updateTxChecksum(txID)
s.addedTxs[txID] = tx
}

Expand Down Expand Up @@ -500,36 +493,6 @@ func (s *state) writeMetadata() error {
return nil
}

func (s *state) Checksums() (ids.ID, ids.ID) {
return s.txChecksum, s.utxoState.Checksum()
}

func (s *state) initTxChecksum() error {
if !s.trackChecksum {
return nil
}

txIt := s.txDB.NewIterator()
defer txIt.Release()

for txIt.Next() {
txIDBytes := txIt.Key()

txID, err := ids.ToID(txIDBytes)
if err != nil {
return err
}

s.updateTxChecksum(txID)
}

return txIt.Error()
}

func (s *state) updateTxChecksum(modifiedID ids.ID) {
if !s.trackChecksum {
return
}

s.txChecksum = s.txChecksum.XOR(modifiedID)
func (s *state) Checksum() ids.ID {
return s.utxoState.Checksum()
}
15 changes: 7 additions & 8 deletions vms/avm/state/statemock/state.go

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

8 changes: 4 additions & 4 deletions vms/platformvm/block/executor/acceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (a *acceptor) ApricotAtomicBlock(b *block.ApricotAtomicBlock) error {
zap.Stringer("blkID", blkID),
zap.Uint64("height", b.Height()),
zap.Stringer("parentID", b.Parent()),
zap.Stringer("utxoChecksum", a.state.Checksum()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files in platformvm feel like an unrelated change... so I can take them out if requested. The rationale for coupling them in this PR was to keep the logging consistent.

zap.Stringer("checksum", a.state.Checksum()),
)

return nil
Expand Down Expand Up @@ -180,7 +180,7 @@ func (a *acceptor) optionBlock(b block.Block, blockType string) error {
zap.Stringer("blkID", blkID),
zap.Uint64("height", b.Height()),
zap.Stringer("parentID", parentID),
zap.Stringer("utxoChecksum", a.state.Checksum()),
zap.Stringer("checksum", a.state.Checksum()),
)

return nil
Expand Down Expand Up @@ -212,7 +212,7 @@ func (a *acceptor) proposalBlock(b block.Block, blockType string) {
zap.Stringer("blkID", blkID),
zap.Uint64("height", b.Height()),
zap.Stringer("parentID", b.Parent()),
zap.Stringer("utxoChecksum", a.state.Checksum()),
zap.Stringer("checksum", a.state.Checksum()),
)
}

Expand Down Expand Up @@ -259,7 +259,7 @@ func (a *acceptor) standardBlock(b block.Block, blockType string) error {
zap.Stringer("blkID", blkID),
zap.Uint64("height", b.Height()),
zap.Stringer("parentID", b.Parent()),
zap.Stringer("utxoChecksum", a.state.Checksum()),
zap.Stringer("checksum", a.state.Checksum()),
)

return nil
Expand Down
Loading