Skip to content

Reduce state/tipset/msg execution/replay/compute APIs in /v2 #13028

@rvagg

Description

@rvagg

Breaking this out from #13027 where I was starting to ramble a bit too much and departing from the issue at hand.


Given we are working on /v2, there's an opportunity to consolidate our msg execution/replay APIs.

We have StateReplay and StateCall and StateCompute today and they all do roughly the same thing but with minor variations, and the internals are becoming very messy to support the variations while keeping backward compatibility, made more complicated by the needs of the Ethereum APIs which want to do similar things.

@Stebalien and I were discussing these the other day trying to boil them down to a single method that we can overload with an options struct argument to support the variations we care about. Then we can push those options down into the core and clean things up a bit.

In #12822 I've replaced a use of StateReplay with StateCall and I'm having to introduce third argument to it just to get my new option in, but in that case I'm introducing an optional struct argument (optional so it's backward compatible as JSONRPC) so I can get the new option in.

callInternal already illustrates the problem if you look both at the number of args, and the number of branches in it:

func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet, stateCid cid.Cid,
- that was most recently complicated by needing a new "strategy" for Ethereum APIs.

Then, if you look at how StateReplay works, you see that it's basically the same thing as StateCall, but with a "execute everything up to this msg" strategy: https://github.com/filecoin-project/lotus/blob/6f09aca67ac53f65004751f55e6aa3c86b349153/chain/stmgr/call.go#L295-L311

StateCompute is something like a StateCall but with an batch of messages and a "apply all messages, then apply these new ones" strategy but also return the new state root.

Right now we're considering at adding a state root to InvocResult as part of solving #13022, which would make ComputeStateOutput redundant.

So, I think we could introduce something like:

StateExecute({
  BaseTipSet, // mandatory
  []ImplicitMessages, // optional, could be used to solve some of our gas estimation bugs
  []Messages, // optional
  TipSetMessageSelectionStrategy, // optional, default to "all", could also be "none", "same sender"
  FlushType, // optional, defaults "none", could be "state", or "all"
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    📌 Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions