Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration for transient data for nv25 #340

Merged
merged 18 commits into from
Jan 30, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
  • Loading branch information
snissn committed Jan 30, 2025
commit 8f44d751c9ea1e87906c816b042cfe0ecd6381a9
41 changes: 29 additions & 12 deletions builtin/v16/evm/evm_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,48 @@ import (
"github.com/filecoin-project/go-state-types/builtin/v16/util/adt"
)

// TransientDataLifespan is a structure representing the transient data lifespan.
// TransientDataLifespan represents the lifespan of transient data.
// It includes the origin actor ID and a nonce to uniquely identify the transaction.
type TransientDataLifespan struct {
Origin abi.ActorID // The origin actor ID associated with the transient data.
Nonce uint64 // A unique nonce identifying the transaction.
Nonce uint64 // A unique nonce identifying the transaction.
}

// TransientData holds the transient state of an EVM contract.
// It includes a CID representing the transient data state and its lifespan.
type TransientData struct {
TransientDataState cid.Cid
TransientDataLifespan TransientDataLifespan
TransientDataState cid.Cid // The contract transient data state CID.
TransientDataLifespan TransientDataLifespan // The lifespan of the transient data.
}

// Tombstone represents a self-destructed contract.
// It stores the origin actor ID and nonce from the message that triggered the self-destruction.
type Tombstone struct {
Origin abi.ActorID
Nonce uint64
Origin abi.ActorID // The message origin when this actor was self-destructed.
Nonce uint64 // The message nonce when this actor was self-destructed.
}

// State defines the storage structure for an EVM contract.
// It contains contract bytecode, contract state, nonce, transient data, and a possible tombstone.
type State struct {
Bytecode cid.Cid
BytecodeHash [32]byte
ContractState cid.Cid
TransientData *TransientData
Nonce uint64
Tombstone *Tombstone
Bytecode cid.Cid // The EVM contract bytecode CID.
BytecodeHash [32]byte // The Keccak256 hash of the contract bytecode.
ContractState cid.Cid // The CID representing the contract's persistent state.
TransientData *TransientData // The transient state of the contract, if any.
Nonce uint64 // The contract nonce used for CREATE/CREATE2.
Tombstone *Tombstone // A tombstone indicating self-destruction, if applicable.
}

// ConstructState initializes a new contract state with the provided bytecode.
// It creates an empty state map and returns the constructed state.
//
// Parameters:
// - store: The ADT store to manage state storage.
// - bytecode: The CID of the contract's bytecode.
//
// Returns:
// - A pointer to the newly constructed State instance.
// - An error if the empty map creation fails.
func ConstructState(store adt.Store, bytecode cid.Cid) (*State, error) {
emptyMapCid, err := adt.StoreEmptyMap(store, builtin.DefaultHamtBitwidth)
if err != nil {
Expand Down