Skip to content

Commit 6e6e50a

Browse files
Remove support for AVM tx checksums (#3774)
Signed-off-by: Joshua Kim <20001595+joshua-kim@users.noreply.github.com> Co-authored-by: Stephen Buttolph <stephen@avalabs.org>
1 parent 4f3f5e7 commit 6e6e50a

File tree

5 files changed

+19
-59
lines changed

5 files changed

+19
-59
lines changed

vms/avm/block/executor/block.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,12 @@ func (b *Block) Accept(context.Context) error {
246246
return err
247247
}
248248

249-
txChecksum, utxoChecksum := b.manager.state.Checksums()
250249
b.manager.backend.Ctx.Log.Trace(
251250
"accepted block",
252251
zap.Stringer("blkID", blkID),
253252
zap.Uint64("height", b.Height()),
254253
zap.Stringer("parentID", b.Parent()),
255-
zap.Stringer("txChecksum", txChecksum),
256-
zap.Stringer("utxoChecksum", utxoChecksum),
254+
zap.Stringer("checksum", b.manager.state.Checksum()),
257255
)
258256
return nil
259257
}

vms/avm/block/executor/block_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ func TestBlockAccept(t *testing.T) {
749749
// because we mock the call to shared memory
750750
mockManagerState.EXPECT().CommitBatch().Return(nil, nil)
751751
mockManagerState.EXPECT().Abort()
752-
mockManagerState.EXPECT().Checksums().Return(ids.Empty, ids.Empty)
752+
mockManagerState.EXPECT().Checksum().Return(ids.Empty)
753753

754754
mockSharedMemory := atomicmock.NewSharedMemory(ctrl)
755755
mockSharedMemory.EXPECT().Apply(gomock.Any(), gomock.Any()).Return(nil)

vms/avm/state/state.go

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ type State interface {
8989
// pending changes to the base database.
9090
CommitBatch() (database.Batch, error)
9191

92-
// Checksums returns the current TxChecksum and UTXOChecksum.
93-
Checksums() (txChecksum ids.ID, utxoChecksum ids.ID)
92+
// Checksum returns the current state checksum.
93+
Checksum() ids.ID
9494

9595
Close() error
9696
}
@@ -134,9 +134,6 @@ type state struct {
134134
lastAccepted, persistedLastAccepted ids.ID
135135
timestamp, persistedTimestamp time.Time
136136
singletonDB database.Database
137-
138-
trackChecksum bool
139-
txChecksum ids.ID
140137
}
141138

142139
func New(
@@ -183,7 +180,7 @@ func New(
183180
return nil, err
184181
}
185182

186-
s := &state{
183+
return &state{
187184
parser: parser,
188185
db: db,
189186

@@ -204,10 +201,7 @@ func New(
204201
blockDB: blockDB,
205202

206203
singletonDB: singletonDB,
207-
208-
trackChecksum: trackChecksums,
209-
}
210-
return s, s.initTxChecksum()
204+
}, nil
211205
}
212206

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

265259
func (s *state) AddTx(tx *txs.Tx) {
266260
txID := tx.ID()
267-
s.updateTxChecksum(txID)
268261
s.addedTxs[txID] = tx
269262
}
270263

@@ -500,36 +493,6 @@ func (s *state) writeMetadata() error {
500493
return nil
501494
}
502495

503-
func (s *state) Checksums() (ids.ID, ids.ID) {
504-
return s.txChecksum, s.utxoState.Checksum()
505-
}
506-
507-
func (s *state) initTxChecksum() error {
508-
if !s.trackChecksum {
509-
return nil
510-
}
511-
512-
txIt := s.txDB.NewIterator()
513-
defer txIt.Release()
514-
515-
for txIt.Next() {
516-
txIDBytes := txIt.Key()
517-
518-
txID, err := ids.ToID(txIDBytes)
519-
if err != nil {
520-
return err
521-
}
522-
523-
s.updateTxChecksum(txID)
524-
}
525-
526-
return txIt.Error()
527-
}
528-
529-
func (s *state) updateTxChecksum(modifiedID ids.ID) {
530-
if !s.trackChecksum {
531-
return
532-
}
533-
534-
s.txChecksum = s.txChecksum.XOR(modifiedID)
496+
func (s *state) Checksum() ids.ID {
497+
return s.utxoState.Checksum()
535498
}

vms/avm/state/statemock/state.go

Lines changed: 7 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vms/platformvm/block/executor/acceptor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (a *acceptor) ApricotAtomicBlock(b *block.ApricotAtomicBlock) error {
110110
zap.Stringer("blkID", blkID),
111111
zap.Uint64("height", b.Height()),
112112
zap.Stringer("parentID", b.Parent()),
113-
zap.Stringer("utxoChecksum", a.state.Checksum()),
113+
zap.Stringer("checksum", a.state.Checksum()),
114114
)
115115

116116
return nil
@@ -180,7 +180,7 @@ func (a *acceptor) optionBlock(b block.Block, blockType string) error {
180180
zap.Stringer("blkID", blkID),
181181
zap.Uint64("height", b.Height()),
182182
zap.Stringer("parentID", parentID),
183-
zap.Stringer("utxoChecksum", a.state.Checksum()),
183+
zap.Stringer("checksum", a.state.Checksum()),
184184
)
185185

186186
return nil
@@ -212,7 +212,7 @@ func (a *acceptor) proposalBlock(b block.Block, blockType string) {
212212
zap.Stringer("blkID", blkID),
213213
zap.Uint64("height", b.Height()),
214214
zap.Stringer("parentID", b.Parent()),
215-
zap.Stringer("utxoChecksum", a.state.Checksum()),
215+
zap.Stringer("checksum", a.state.Checksum()),
216216
)
217217
}
218218

@@ -259,7 +259,7 @@ func (a *acceptor) standardBlock(b block.Block, blockType string) error {
259259
zap.Stringer("blkID", blkID),
260260
zap.Uint64("height", b.Height()),
261261
zap.Stringer("parentID", b.Parent()),
262-
zap.Stringer("utxoChecksum", a.state.Checksum()),
262+
zap.Stringer("checksum", a.state.Checksum()),
263263
)
264264

265265
return nil

0 commit comments

Comments
 (0)