Skip to content
Open
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
1 change: 1 addition & 0 deletions execution/state/intra_block_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -3658,6 +3658,7 @@ func (ibs *IntraBlockState) PublishOrigins() {
}
}
})
ws.ReleaseAndReset()
}

// Apply entries in a given write set to StateDB. Note that this function does not change MVHashMap nor write set
Expand Down
29 changes: 29 additions & 0 deletions execution/state/storage_origin_seed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,32 @@ func TestStorageCommittedReadSeedsOrigin(t *testing.T) {
require.Equal(t, originIndex, res.DepIdx())
require.Equal(t, committed, got)
}

// A state reused across the txs of a block must publish each origin once:
// FinalizedWrites hands the tx's origin cells to the versionMap, so the next
// tx does not publish them again.
func TestFinalizedWritesHandsOverOrigins(t *testing.T) {
addr := accounts.InternAddress([20]byte{0xA0, 0xb8})
key := accounts.InternKey([32]byte{0x03})
acc := accounts.NewAccount()
acc.Nonce = 1
committed := *uint256.NewInt(11)

reader := &storageReader{
addr: addr,
account: &acc,
storage: map[accounts.StorageKey]uint256.Int{key: committed},
}
ibs := NewWithVersionMap(reader, NewVersionMap(nil))
ibs.SetTxContext(100, 0)

_, err := ibs.GetState(addr, key)
require.NoError(t, err)
_, err = ibs.FinalizedWrites(nil)
require.NoError(t, err)

require.True(t, ibs.versionedOrigins.IsEmpty(), "published origins must not be kept for the next tx")
got, ok := ibs.versionMap.LoadOriginStorage(addr, key)
require.True(t, ok)
require.Equal(t, committed, got)
}
Loading