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

chore: upgrade to the latest go-f3 and allow F3 chain exchange topics #12839

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions api/docgen-openrpc/openrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/ipfs/go-cid"
meta_schema "github.com/open-rpc/meta-schema"

"github.com/filecoin-project/go-f3/gpbft"

"github.com/filecoin-project/lotus/api/docgen"
"github.com/filecoin-project/lotus/build"
)
Expand All @@ -29,6 +31,40 @@ const integerD = `{
"description": "Number is a number"
}`

const f3ECChain = `{
"items": {
"additionalProperties": false,
"properties": {
"Commitments": {
"items": {
"description": "Number is a number",
"title": "number",
"type": "number"
},
"maxItems": 32,
"minItems": 32,
"type": "array"
},
"Epoch": {
"title": "number",
"type": "number"
},
"Key": {
"media": {
"binaryEncoding": "base64"
},
"type": "string"
},
"PowerTable": {
"title": "Content Identifier",
"type": "string"
}
},
"type": "object"
},
"type": "array"
}`

const cidCidD = `{"title": "Content Identifier", "type": "string", "description": "Cid represents a self-describing content addressed identifier. It is formed by a Version, a Codec (which indicates a multicodec-packed content type) and a Multihash."}`

func Generate(out io.Writer, iface, pkg string, ainfo docgen.ApiASTInfo, outGzip bool) error {
Expand Down Expand Up @@ -84,6 +120,7 @@ func OpenRPCSchemaTypeMapper(ty reflect.Type) *jsonschema.Type {
// Use a slice instead of a map because it preserves order, as a logic safeguard/fallback.
dict := []schemaDictEntry{
{cid.Cid{}, cidCidD},
{gpbft.ECChain{}, f3ECChain},
}

for _, d := range dict {
Expand Down
12 changes: 7 additions & 5 deletions api/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ func init() {

f3Cert := certs.FinalityCertificate{
GPBFTInstance: 0,
ECChain: []gpbft.TipSet{
{
Epoch: 0,
Key: tsk.Bytes(),
PowerTable: c,
ECChain: &gpbft.ECChain{
TipSets: []*gpbft.TipSet{
{
Epoch: 0,
Key: tsk.Bytes(),
PowerTable: c,
},
},
},
SupplementalData: gpbft.SupplementalData{
Expand Down
2 changes: 1 addition & 1 deletion build/buildconstants/params_butterfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ var F3ManifestServerID = MustParseID("12D3KooWJr9jy4ngtJNR7JC1xgLFra3DjEtyxskRYW
// The initial F3 power table CID.
var F3InitialPowerTableCID cid.Cid = cid.Undef

const F3BootstrapEpoch abi.ChainEpoch = 1000
const F3BootstrapEpoch abi.ChainEpoch = -1
Binary file modified build/genesis/butterflynet.car.zst
Binary file not shown.
64 changes: 64 additions & 0 deletions build/openrpc/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -7588,7 +7588,9 @@
"Gpbft": {
"Delta": 0,
"DeltaBackOffExponent": 0,
"QualityDeltaMultiplier": 0,
"MaxLookaheadRounds": 0,
"ChainProposedLength": 0,
"RebroadcastBackoffBase": 0,
"RebroadcastBackoffExponent": 0,
"RebroadcastBackoffSpread": 0,
Expand All @@ -7607,6 +7609,18 @@
"ServerRequestTimeout": 0,
"MinimumPollInterval": 0,
"MaximumPollInterval": 0
},
"PubSub": {
"CompressionEnabled": false
},
"ChainExchange": {
"SubscriptionBufferSize": 0,
"MaxChainLength": 0,
"MaxInstanceLookahead": 0,
"MaxDiscoveredChainsPerInstance": 0,
"MaxWantedChainsPerInstance": 0,
"RebroadcastInterval": 0,
"MaxTimestampAge": 0
}
}
],
Expand Down Expand Up @@ -7642,6 +7656,40 @@
},
"type": "object"
},
"ChainExchange": {
"additionalProperties": false,
"properties": {
"MaxChainLength": {
"title": "number",
"type": "number"
},
"MaxDiscoveredChainsPerInstance": {
"title": "number",
"type": "number"
},
"MaxInstanceLookahead": {
"title": "number",
"type": "number"
},
"MaxTimestampAge": {
"title": "number",
"type": "number"
},
"MaxWantedChainsPerInstance": {
"title": "number",
"type": "number"
},
"RebroadcastInterval": {
"title": "number",
"type": "number"
},
"SubscriptionBufferSize": {
"title": "number",
"type": "number"
}
},
"type": "object"
},
"CommitteeLookback": {
"title": "number",
"type": "number"
Expand Down Expand Up @@ -7704,6 +7752,10 @@
"Gpbft": {
"additionalProperties": false,
"properties": {
"ChainProposedLength": {
"title": "number",
"type": "number"
},
"Delta": {
"title": "number",
"type": "number"
Expand All @@ -7715,6 +7767,9 @@
"title": "number",
"type": "number"
},
"QualityDeltaMultiplier": {
"type": "number"
},
"RebroadcastBackoffBase": {
"title": "number",
"type": "number"
Expand Down Expand Up @@ -7752,6 +7807,15 @@
"ProtocolVersion": {
"title": "number",
"type": "number"
},
"PubSub": {
"additionalProperties": false,
"properties": {
"CompressionEnabled": {
"type": "boolean"
}
},
"type": "object"
}
},
"type": [
Expand Down
12 changes: 12 additions & 0 deletions chain/lf3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ func NewManifest(
MinimumPollInterval: ecPeriod,
MaximumPollInterval: 4 * ecPeriod,
},
PubSub: manifest.PubSubConfig{
CompressionEnabled: true,
},
ChainExchange: manifest.ChainExchangeConfig{
SubscriptionBufferSize: 32,
MaxChainLength: gpbft.ChainDefaultLen,
MaxInstanceLookahead: manifest.DefaultCommitteeLookback,
MaxDiscoveredChainsPerInstance: 1_000,
MaxWantedChainsPerInstance: 1_000,
RebroadcastInterval: 2 * time.Second,
MaxTimestampAge: 8 * time.Second,
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion chain/lf3/f3.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (fff *F3) GetLatestCert(ctx context.Context) (*certs.FinalityCertificate, e
func (fff *F3) GetManifest(ctx context.Context) (*manifest.Manifest, error) {
m := fff.inner.Manifest()
if m == nil {
return nil, xerrors.New("no known network manifest")
return nil, manifest.ErrNoManifest
}
if m.InitialPowerTable.Defined() {
return m, nil
Expand Down
11 changes: 7 additions & 4 deletions cli/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/signal"
"syscall"

logging "github.com/ipfs/go-log/v2"
ufcli "github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -46,11 +47,13 @@ func RunApp(app *ufcli.App) {
}()

if err := app.Run(os.Args); err != nil {
if os.Getenv("LOTUS_DEV") != "" {
log.Warnf("%+v", err)
} else {
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err) // nolint:errcheck
if cfg := logging.GetConfig(); !(cfg.Stdout || cfg.Stderr) {
// To avoid printing the error twice while making sure that log file contains the
// error, check the config and only print it if the output isn't stderr or
// stdout.
log.Errorw("Failed to start application", "err", err)
}
_, _ = fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
var phe *PrintHelpErr
if errors.As(err, &phe) {
_ = ufcli.ShowCommandHelp(phe.Ctx, phe.Ctx.Command.Name)
Expand Down
4 changes: 2 additions & 2 deletions cli/templates/f3_finality_cert.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ Power Table:
Next: {{.SupplementalData.PowerTable}}
Delta: {{ptDiffToString .PowerTableDelta}}
Finalized Chain:
Length: {{ $chainLength := len .ECChain -}}{{ $chainLength }}
Length: {{ $chainLength := len .ECChain.TipSets -}}{{ $chainLength }}
Epochs: {{ .ECChain.Base.Epoch -}}-{{ .ECChain.Head.Epoch }}
Chain:
{{- $maxTipSets := 10 -}}
{{- $maxTipSetKeys := 2 -}}
{{- range $i, $tipset := .ECChain -}}
{{- range $i, $tipset := .ECChain.TipSets -}}
{{- if lt $i $maxTipSets -}}
{{- if lt (add $i 1) $chainLength }}
├──
Expand Down
12 changes: 12 additions & 0 deletions cli/templates/f3_manifest.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Manifest:

GPBFT Delta: {{.Gpbft.Delta}}
GPBFT Delta BackOff Exponent: {{.Gpbft.DeltaBackOffExponent}}
GPBFT Quality Delta Multiplier: {{.Gpbft.QualityDeltaMultiplier}}
GPBFT Max Lookahead Rounds: {{.Gpbft.MaxLookaheadRounds}}
GPBFT Chain Proposed Length: {{.Gpbft.ChainProposedLength}}
GPBFT Rebroadcast Backoff Base: {{.Gpbft.RebroadcastBackoffBase}}
GPBFT Rebroadcast Backoff Exponent: {{.Gpbft.RebroadcastBackoffExponent}}
GPBFT Rebroadcast Backoff Spread: {{.Gpbft.RebroadcastBackoffSpread}}
Expand All @@ -27,3 +29,13 @@ Manifest:
Certificate Exchange Server Timeout: {{.CertificateExchange.ServerRequestTimeout}}
Certificate Exchange Min Poll Interval: {{.CertificateExchange.MinimumPollInterval}}
Certificate Exchange Max Poll Interval: {{.CertificateExchange.MaximumPollInterval}}

PubSub Compression Enabled: {{.PubSub.CompressionEnabled}}

Chain Exchange Subscription Buffer Size: {{.ChainExchange.SubscriptionBufferSize}}
Chain Exchange Max Chain Length: {{.ChainExchange.MaxChainLength}}
Chain Exchange Max Instance Lookahead: {{.ChainExchange.MaxInstanceLookahead}}
Chain Exchange Max Discovered Chains Per Instance: {{.ChainExchange.MaxDiscoveredChainsPerInstance}}
Chain Exchange Max Wanted Chains Per Instance: {{.ChainExchange.MaxWantedChainsPerInstance}}
Chain Exchange Rebroadcast Interval: {{.ChainExchange.RebroadcastInterval}}
Chain Exchange Max Timestamp Age: {{.ChainExchange.MaxTimestampAge}}
14 changes: 14 additions & 0 deletions documentation/en/api-v1-unstable-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -2624,7 +2624,9 @@ Response:
"Gpbft": {
"Delta": 0,
"DeltaBackOffExponent": 0,
"QualityDeltaMultiplier": 0,
"MaxLookaheadRounds": 0,
"ChainProposedLength": 0,
"RebroadcastBackoffBase": 0,
"RebroadcastBackoffExponent": 0,
"RebroadcastBackoffSpread": 0,
Expand All @@ -2643,6 +2645,18 @@ Response:
"ServerRequestTimeout": 0,
"MinimumPollInterval": 0,
"MaximumPollInterval": 0
},
"PubSub": {
"CompressionEnabled": false
},
"ChainExchange": {
"SubscriptionBufferSize": 0,
"MaxChainLength": 0,
"MaxInstanceLookahead": 0,
"MaxDiscoveredChainsPerInstance": 0,
"MaxWantedChainsPerInstance": 0,
"RebroadcastInterval": 0,
"MaxTimestampAge": 0
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
github.com/filecoin-project/go-cbor-util v0.0.1
github.com/filecoin-project/go-commp-utils/v2 v2.1.0
github.com/filecoin-project/go-crypto v0.1.0
github.com/filecoin-project/go-f3 v0.7.3
github.com/filecoin-project/go-f3 v0.7.4-0.20250207110112-a2b3c6601f7f
github.com/filecoin-project/go-fil-commcid v0.2.0
github.com/filecoin-project/go-hamt-ipld/v3 v3.4.0
github.com/filecoin-project/go-jsonrpc v0.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ github.com/filecoin-project/go-commp-utils/v2 v2.1.0/go.mod h1:NbxJYlhxtWaNhlVCj
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03/go.mod h1:+viYnvGtUTgJRdy6oaeF4MTFKAfatX071MPDPBL11EQ=
github.com/filecoin-project/go-crypto v0.1.0 h1:Pob2MphoipMbe/ksxZOMcQvmBHAd3sI/WEqcbpIsGI0=
github.com/filecoin-project/go-crypto v0.1.0/go.mod h1:K9UFXvvoyAVvB+0Le7oGlKiT9mgA5FHOJdYQXEE8IhI=
github.com/filecoin-project/go-f3 v0.7.3 h1:nwRYRKaJs7AV3di/OQyj6tABeixBeL06DkJeoQrr5+0=
github.com/filecoin-project/go-f3 v0.7.3/go.mod h1:wDo5mPi4KXVuA7kvwLpmfVVv2Aw2ZwZk3iqMWr5BOT0=
github.com/filecoin-project/go-f3 v0.7.4-0.20250207110112-a2b3c6601f7f h1:XK3TQ8SUBpE91deUqe3QQjD4ZNNMWhCf2Ts1YGtqCzI=
github.com/filecoin-project/go-f3 v0.7.4-0.20250207110112-a2b3c6601f7f/go.mod h1:zNFGuBM+fYuGXk2fpzl6wW4g2Gyrxgg6z2IVSoGt+60=
github.com/filecoin-project/go-fil-commcid v0.2.0 h1:B+5UX8XGgdg/XsdUpST4pEBviKkFOw+Fvl2bLhSKGpI=
github.com/filecoin-project/go-fil-commcid v0.2.0/go.mod h1:8yigf3JDIil+/WpqR5zoKyP0jBPCOGtEqq/K1CcMy9Q=
github.com/filecoin-project/go-fil-commp-hashhash v0.2.0 h1:HYIUugzjq78YvV3vC6rL95+SfC/aSTVSnZSZiDV5pCk=
Expand Down
15 changes: 10 additions & 5 deletions itests/f3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"golang.org/x/sync/errgroup"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-f3"
"github.com/filecoin-project/go-f3/certs"
"github.com/filecoin-project/go-f3/gpbft"
"github.com/filecoin-project/go-f3/manifest"
Expand Down Expand Up @@ -99,10 +100,10 @@ func TestF3_InactiveModes(t *testing.T) {
expectedErrors: map[string]any{
"F3GetOrRenewParticipationTicket": api.ErrF3NotReady,
"F3Participate": api.ErrF3NotReady,
"F3GetCertificate": "F3 is not running",
"F3GetLatestCertificate": "F3 is not running",
"F3GetManifest": "no known network manifest",
"F3GetF3PowerTable": "no known network manifest",
"F3GetCertificate": f3.ErrF3NotRunning.Error(),
"F3GetLatestCertificate": f3.ErrF3NotRunning.Error(),
"F3GetManifest": manifest.ErrNoManifest.Error(),
"F3GetF3PowerTable": manifest.ErrNoManifest.Error(),
},
expectedValues: map[string]any{
"F3GetOrRenewParticipationTicket": (api.F3ParticipationTicket)(nil),
Expand Down Expand Up @@ -343,7 +344,7 @@ func (e *testEnv) waitTillF3Instance(i uint64, timeout time.Duration) {
e.waitFor(func(n *kit.TestFullNode) bool {
c, err := n.F3GetLatestCertificate(e.testCtx)
if err != nil {
require.ErrorContains(e.t, err, "F3 is not running")
require.ErrorContains(e.t, err, f3.ErrF3NotRunning.Error())
return false
}
return c != nil && c.GPBFTInstance >= i
Expand Down Expand Up @@ -451,7 +452,9 @@ func newTestManifest(networkName gpbft.NetworkName, bootstrapEpoch int64, blockt
// Use smaller time intervals for more responsive test progress/assertion.
Delta: 250 * time.Millisecond,
DeltaBackOffExponent: 1.3,
QualityDeltaMultiplier: manifest.DefaultGpbftConfig.QualityDeltaMultiplier,
MaxLookaheadRounds: 5,
ChainProposedLength: manifest.DefaultGpbftConfig.ChainProposedLength,
RebroadcastBackoffBase: 500 * time.Millisecond,
RebroadcastBackoffSpread: 0.1,
RebroadcastBackoffExponent: 1.3,
Expand All @@ -471,6 +474,8 @@ func newTestManifest(networkName gpbft.NetworkName, bootstrapEpoch int64, blockt
MinimumPollInterval: blocktime,
MaximumPollInterval: 4 * blocktime,
},
PubSub: manifest.DefaultPubSubConfig,
ChainExchange: manifest.DefaultChainExchangeConfig,
}
}

Expand Down
Loading
Loading