Skip to content

Commit d8f90c5

Browse files
committed
Implement initial Lotus V2 State APIs
Implement the Lotus V2 APIs for : * `StateGetActor` - enhanced to accept tipset selector. * `StateGetID` - enhanced to accept tipset selector / renamed from `LookupID` in v1 for consistency. * `StateSimulate` - enhanced to accept tipset selector, and separated out of v1 `StateCompute` to focus solely on simulation of compute for future instances. Additionally, it accepts a limit either relative or absolute for how far to simulate. * `StateCompute` - enhanced to accept tipset selector, and changed to purely apply state at given tipset based on a common usage pattern across exchanges. This function now implicitly computes for the height of the given tipset. For simulation of future heights, use `StateSimulate`. Tests are added to exercise the end-to-end API call through JSON rpc with the raw wire format of the JSON-RPC request. Additional factory functions are added for `TipSetLimit`, a new concept to specify a limit for tipsets either as absolute height or relative to some tipset selector. The future State message search APIs in v2 aim to use Limit in upcoming PRs.
1 parent a1f1d51 commit d8f90c5

File tree

13 files changed

+2904
-184
lines changed

13 files changed

+2904
-184
lines changed

api/docgen/docgen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ func init() {
470470
Input: ecchain,
471471
})
472472
addExample(types.TipSetSelectors.Finalized)
473+
addExample(types.TipSetLimits.Height(1413))
473474
}
474475

475476
func GetAPIType(name, pkg string) (i interface{}, t reflect.Type, permStruct []reflect.Type) {

api/v2api/full.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package v2api
33
import (
44
"context"
55

6+
"github.com/filecoin-project/go-address"
7+
8+
"github.com/filecoin-project/lotus/api"
69
"github.com/filecoin-project/lotus/chain/types"
710
)
811

@@ -49,4 +52,108 @@ type FullNode interface {
4952
// fmt.Printf("Latest TipSet: %v\n", tipSet)
5053
//
5154
ChainGetTipSet(context.Context, types.TipSetSelector) (*types.TipSet, error) //perm:read
55+
56+
// MethodGroup: State
57+
// The State method group contains methods for interacting with the Filecoin
58+
// blockchain state, including actor information, addresses, and chain data.
59+
// These methods allow querying the blockchain state at any point in its history
60+
// using flexible TipSet selection mechanisms.
61+
62+
// StateGetActor retrieves the actor information for the specified address at the
63+
// selected tipset.
64+
//
65+
// This function returns the on-chain Actor object including:
66+
// - Code CID (determines the actor's type)
67+
// - State root CID
68+
// - Balance in attoFIL
69+
// - Nonce (for account actors)
70+
//
71+
// The TipSetSelector parameter provides flexible options for selecting the tipset:
72+
// - TipSetSelectors.Latest: the most recent tipset with the heaviest weight
73+
// - TipSetSelectors.Finalized: the most recent finalized tipset
74+
// - TipSetSelectors.Height(epoch, previous, anchor): tipset at the specified height
75+
// - TipSetSelectors.Key(key): tipset with the specified key
76+
//
77+
// See types.TipSetSelector documentation for additional details.
78+
//
79+
// If the actor does not exist at the specified tipset, this function returns nil.
80+
//
81+
// Experimental: This API is experimental and may change without notice.
82+
StateGetActor(context.Context, address.Address, types.TipSetSelector) (*types.Actor, error) //perm:read
83+
84+
// StateGetID retrieves the ID address for the specified address at the selected tipset.
85+
//
86+
// Every actor on the Filecoin network has a unique ID address (format: f0123).
87+
// This function resolves any address type (ID, robust, or delegated) to its canonical
88+
// ID address representation at the specified tipset.
89+
//
90+
// The function is particularly useful for:
91+
// - Normalizing different address formats to a consistent representation
92+
// - Following address changes across state transitions
93+
// - Verifying that an address corresponds to an existing actor
94+
//
95+
// The TipSetSelector parameter provides flexible options for selecting the tipset.
96+
// See StateGetActor documentation for details on selection options.
97+
//
98+
// If the address cannot be resolved at the specified tipset, this function returns nil.
99+
//
100+
// Experimental: This API is experimental and may change without notice.
101+
StateGetID(context.Context, address.Address, types.TipSetSelector) (*address.Address, error) //perm:read
102+
103+
// StateCompute computes the state at the specified tipset and applies the provided messages.
104+
//
105+
// This function:
106+
// - Loads the tipset identified by the TipSetSelector
107+
// - Calculates the complete state by applying all chain messages within that tipset
108+
// - Applies the user-provided messages on top of that state
109+
// - Uses the network version of the selected tipset for message execution
110+
//
111+
// The function applies messages with the correct network parameters corresponding
112+
// to the tipset's epoch, making it suitable for testing messages against the
113+
// current network version.
114+
//
115+
// Messages must have the correct nonces and gas values set.
116+
//
117+
// The TipSetSelector parameter provides flexible options for selecting the base tipset:
118+
// - TipSetSelectors.Latest: the most recent tipset with the heaviest weight
119+
// - TipSetSelectors.Finalized: the most recent finalized tipset
120+
// - TipSetSelectors.Height(epoch, previous, anchor): tipset at the specified height
121+
// - TipSetSelectors.Key(key): tipset with the specified key
122+
//
123+
// See types.TipSetSelector documentation for additional details.
124+
//
125+
// Experimental: This API is experimental and may change without notice.
126+
StateCompute(context.Context, []*types.Message, types.TipSetSelector) (*api.ComputeStateOutput, error) //perm:read
127+
128+
// StateSimulate computes the state at the specified tipset and applies the provided messages
129+
// using the network version determined by a TipSetLimit.
130+
//
131+
// This function:
132+
// - Loads the tipset identified by the TipSetSelector
133+
// - Calculates the complete state by applying all chain messages within that tipset
134+
// - Applies any pending state upgrades up to the epoch determined by TipSetLimit
135+
// - Applies the user-provided messages on top of that state using the network version
136+
// corresponding to the target epoch
137+
//
138+
// This function is particularly useful for testing how messages would behave in
139+
// future network versions or for simulating execution at specific protocol versions.
140+
//
141+
// The TipSetLimit parameter controls the simulation target and must specify exactly
142+
// one of the following:
143+
// - Height: an absolute chain epoch at which to simulate execution
144+
// - Distance: a relative number of epochs ahead of the selected tipset
145+
//
146+
// For example, to simulate at exactly epoch 1000, use Height=1000. To simulate
147+
// 120 epochs ahead of the selected tipset, use Distance=120.
148+
//
149+
// If the target epoch determined by TipSetLimit is lower than the tipset's epoch,
150+
// an error will be returned as backward simulation is not supported.
151+
//
152+
// Messages must have the correct nonces and gas values set.
153+
//
154+
// The TipSetSelector parameter provides flexible options for selecting the base tipset.
155+
// See StateCompute and TipSetSelector documentation for details on selection options.
156+
//
157+
// Experimental: This API is experimental and may change without notice.
158+
StateSimulate(context.Context, []*types.Message, types.TipSetSelector, types.TipSetLimit) (*api.ComputeStateOutput, error) //perm:read
52159
}

api/v2api/proxy_gen.go

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

api/v2api/v2mocks/mock_full.go

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

0 commit comments

Comments
 (0)