Skip to content

Commit

Permalink
fix: support Forrest parity testing for F3 participation APIs (#12615)
Browse files Browse the repository at this point in the history
* Support Forrest parity testing for F3 participation APIs

For parity testing, Forest nodes need to decode an F3 participation
ticket that is issued by Lotus. Lotus so happens to use CBOR to encode
tickets, which it then decodes to issue a lease.

The lease issuer is of type `peer.ID` which is an alias of type `string`
that may contain non UTF-8 characters. If this type is used directly in
CBOR encoding then it gets encoded as string, which works fine in Golang
but not Rust, which in turn results in decoding issues in Forest.

To avoid this use `[]byte` as the type to encode the issuer public key.
In Lotus, the value will be the binary marshalling of `peer.ID` that
issued the ticket.

While at it, also fix two issues that were brought up during discussion:

* A miner must not be able to ask for a ticket to participate in zero
  instances. Validate and return error if instances is set to zero.

* Use CBOR tuple encoding for a slightly better efficient wire encoding
  of ticket. `cborgen.Write*` APIs explicitly create a given file; hence
  the need to separate the file to which tuple kinds are generated since
  the existing encoding for types in `api/cbor_gen.go` use maps.
  • Loading branch information
masih authored and rjan90 committed Oct 28, 2024
1 parent c3dd966 commit 45bac64
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 253 deletions.
11 changes: 5 additions & 6 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p/core/peer"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
Expand Down Expand Up @@ -923,9 +922,9 @@ type FullNode interface {
//
// If there is an issuer mismatch (ErrF3ParticipationIssuerMismatch), the miner
// must retry obtaining a new ticket to ensure it is only participating in one F3
// instance at any time. If the number of instances is beyond the maximum leasable
// participation instances accepted by the node ErrF3ParticipationTooManyInstances
// is returned.
// instance at any time. The number of instances must be at least 1. If the
// number of instances is beyond the maximum leasable participation instances
// accepted by the node ErrF3ParticipationTooManyInstances is returned.
//
// Note: Successfully acquiring a ticket alone does not constitute participation.
// The retrieved ticket must be used to invoke F3Participate to actively engage
Expand Down Expand Up @@ -980,8 +979,8 @@ type F3ParticipationTicket []byte
type F3ParticipationLease struct {
// Network is the name of the network this lease belongs to.
Network gpbft.NetworkName
// Issuer is the identity of the node that issued the lease.
Issuer peer.ID
// Issuer is the identity of the node that issued the lease, encoded as base58.
Issuer string
// MinerID is the actor ID of the miner that holds the lease.
MinerID uint64
// FromInstance specifies the instance ID from which this lease is valid.
Expand Down
225 changes: 0 additions & 225 deletions api/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 45bac64

Please sign in to comment.