Files
lotus/documentation/en/api-v2-unstable-methods.md
Masih H. Derkani a1f1d51b73 feat: implement ChainGetTipSet in Lotus v2 APIs (#13003)
Introduce the first API for Lotus v2, focusing on `ChainGetTipSet`
within the `Chain` group. Define `TipSetSelector` for advanced
tipset retrieval options, and create a compact JSON-RPC call format.

Gracefully accommodate both EC and F3 finalized tipsets based on node
configuration, where:
* EC finalized tipset is returned when F3 is turned off, has no
  finalized tipset or F3 isn't ready.
* F3 finalized is returned otherwise.

Support three categories of selectors under `TipSetSelector`:
* By tag: either "latest" or "finalized."
* By height: epoch, plus optional fallback to previous non-null tipset.
* By tipset key.

The selection falls back to tag "latest" if the user specifies no
selection criterion.

The JSON-RPC format is designed to use JSON Object as the parameters
passed to the RPC call to remain compact, and extensible.
2025-04-09 17:08:59 +01:00

1.6 KiB

Groups

Chain

The Chain method group contains methods for interacting with the blockchain.

Note: This API is experimental and may change in the future.

Please see Filecoin V2 API design documentation for more details:

ChainGetTipSet

ChainGetTipSet retrieves a tipset that corresponds to the specified selector criteria. The criteria can be provided in the form of a tipset key, a blockchain height including an optional fallback to previous non-null tipset, or a designated tag such as "latest" or "finalized".

The "Finalized" tag returns the tipset that is considered finalized based on the consensus protocol of the current node, either Filecoin EC Finality or Filecoin Fast Finality (F3). The finalized tipset selection gracefully falls back to EC finality in cases where F3 isn't ready or not running.

In a case where no selector is provided, an error is returned. The selector must be explicitly specified.

For more details, refer to the types.TipSetSelector and types.NewTipSetSelector.

Example usage:

selector := types.TipSetSelectors.Latest
tipSet, err := node.ChainGetTipSet(context.Background(), selector)
if err != nil {
	fmt.Println("Error retrieving tipset:", err)
	return
}
fmt.Printf("Latest TipSet: %v\n", tipSet)

Perms: read

Inputs:

[
  {
    "tag": "finalized"
  }
]

Response:

{
  "Cids": null,
  "Blocks": null,
  "Height": 0
}