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

feat: implement Filecoin.GetParentMessages RPC API(server side) #3720

Merged
merged 5 commits into from
Nov 21, 2023

Conversation

hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Nov 16, 2023

Summary of changes

As part of #3639

Changes introduced in this pull request:

  • implement Filecoin.GetParentMessages RPC API(server side) that is compatible with lotus
Running `target/debug/forest-tool api compare /home/me/fr/snapshots/calibnet/forest_snapshot_calibnet_2023-11-16_height_1093103.forest.car.zst --filter ChainGet`
| RPC Method                             | Forest | Lotus |
|----------------------------------------|--------|-------|
| Filecoin.ChainGetBlock                 | Valid  | Valid |
| Filecoin.ChainGetBlockMessages (49)    | Valid  | Valid |
| Filecoin.ChainGetGenesis               | Valid  | Valid |
| Filecoin.ChainGetMessage (12)          | Valid  | Valid |
| Filecoin.ChainGetMessagesInTipset (20) | Valid  | Valid |
| Filecoin.ChainGetParentMessages (49)   | Valid  | Valid |
| Filecoin.ChainGetTipSet                | Valid  | Valid |
| Filecoin.ChainGetTipSetByHeight        | Valid  | Valid |

Lotus code:

func (a *ChainAPI) ChainGetParentMessages(ctx context.Context, bcid cid.Cid) ([]api.Message, error) {
	b, err := a.Chain.GetBlock(ctx, bcid)
	if err != nil {
		return nil, err
	}

	// genesis block has no parent messages...
	if b.Height == 0 {
		return nil, nil
	}

	// TODO: need to get the number of messages better than this
	pts, err := a.Chain.LoadTipSet(ctx, types.NewTipSetKey(b.Parents...))
	if err != nil {
		return nil, err
	}

	cm, err := a.Chain.MessagesForTipset(ctx, pts)
	if err != nil {
		return nil, err
	}

	var out []api.Message
	for _, m := range cm {
		out = append(out, api.Message{
			Cid:     m.Cid(),
			Message: m.VMMessage(),
		})
	}

	return out, nil
}

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@hanabi1224 hanabi1224 marked this pull request as ready for review November 16, 2023 08:06
@hanabi1224 hanabi1224 requested a review from a team as a code owner November 16, 2023 08:06
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and sudo-shashank and removed request for a team November 16, 2023 08:06
@ruseinov ruseinov self-requested a review November 16, 2023 11:21
@LesnyRumcajs
Copy link
Member

Should we add a changelog entry?

@hanabi1224
Copy link
Contributor Author

Should we add a changelog entry?

@LesnyRumcajs Changelog updated. Please re-approve if it looks good.

@hanabi1224 hanabi1224 added this pull request to the merge queue Nov 21, 2023
Merged via the queue into main with commit 390221f Nov 21, 2023
27 checks passed
@hanabi1224 hanabi1224 deleted the hm/api-get-parent-messages branch November 21, 2023 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants