-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88dcaaf
commit b1b5899
Showing
11 changed files
with
506 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/go,rust | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=go,rust | ||
|
||
### Go ### | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
vendor/ | ||
|
||
# Go workspace file | ||
# go.work | ||
|
||
### Rust ### | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/go,rust |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### EC tests | ||
|
||
- run a forest node locally and expose RPC port and the default 2345 | ||
- run `go test -v .` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/filecoin-project/go-f3/gpbft" | ||
) | ||
|
||
type F3Api struct { | ||
GetTipsetByEpoch func(context.Context, int64) (TipSet, error) | ||
GetTipset func(context.Context, gpbft.TipSetKey) (TipSet, error) | ||
GetHead func(context.Context) (TipSet, error) | ||
GetParent func(context.Context, gpbft.TipSetKey) (TipSet, error) | ||
GetPowerTable func(context.Context, gpbft.TipSetKey) (gpbft.PowerEntries, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/filecoin-project/go-f3/ec" | ||
"github.com/filecoin-project/go-f3/gpbft" | ||
"github.com/filecoin-project/go-jsonrpc" | ||
) | ||
|
||
type ForestEC struct { | ||
rpcEndpoint string | ||
f3api F3Api | ||
closer jsonrpc.ClientCloser | ||
} | ||
|
||
func NewForestEC(rpcEndpoint string) (ForestEC, error) { | ||
f3api := F3Api{} | ||
closer, err := jsonrpc.NewClient(context.Background(), rpcEndpoint, "F3", &f3api, nil) | ||
if err != nil { | ||
return ForestEC{}, err | ||
} | ||
return ForestEC{rpcEndpoint, f3api, closer}, nil | ||
} | ||
|
||
func (ec *ForestEC) Close() { | ||
ec.closer() | ||
} | ||
|
||
func (ec *ForestEC) GetTipsetByEpoch(ctx context.Context, epoch int64) (ec.TipSet, error) { | ||
return ec.f3api.GetTipsetByEpoch(ctx, epoch) | ||
} | ||
|
||
func (ec *ForestEC) GetTipset(ctx context.Context, tsk gpbft.TipSetKey) (ec.TipSet, error) { | ||
return ec.f3api.GetTipset(ctx, tsk) | ||
} | ||
|
||
func (ec *ForestEC) GetHead(ctx context.Context) (ec.TipSet, error) { | ||
return ec.f3api.GetHead(ctx) | ||
} | ||
|
||
func (ec *ForestEC) GetParent(ctx context.Context, tsk gpbft.TipSetKey) (ec.TipSet, error) { | ||
return ec.f3api.GetParent(ctx, tsk) | ||
} | ||
|
||
func (ec *ForestEC) GetPowerTable(ctx context.Context, tsk gpbft.TipSetKey) (gpbft.PowerEntries, error) { | ||
return ec.f3api.GetPowerTable(ctx, tsk) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
EC ForestEC | ||
ctx = context.Background() | ||
) | ||
|
||
func init() { | ||
ec, err := NewForestEC("http://localhost:2345/rpc/v1") | ||
if err != nil { | ||
panic(err) | ||
} | ||
EC = ec | ||
} | ||
|
||
func TestGetTipsetByEpoch(t *testing.T) { | ||
head, err := EC.GetHead(ctx) | ||
require.NoError(t, err) | ||
ts, err := EC.GetTipsetByEpoch(ctx, head.Epoch()-10) | ||
require.NoError(t, err) | ||
fmt.Printf("GetTipsetByEpoch: %s\n", ts) | ||
} | ||
|
||
func TestGetHead(t *testing.T) { | ||
head, err := EC.GetHead(ctx) | ||
require.NoError(t, err) | ||
fmt.Printf("GetHead: %s\n", head) | ||
} | ||
|
||
func TestGetTipset(t *testing.T) { | ||
head, err := EC.GetHead(ctx) | ||
require.NoError(t, err) | ||
ts, err := EC.GetTipset(ctx, head.Key()) | ||
require.NoError(t, err) | ||
require.Equal(t, head, ts) | ||
fmt.Printf("GetTipset: %s\n", ts) | ||
} | ||
|
||
func TestGetParent(t *testing.T) { | ||
head, err := EC.GetHead(ctx) | ||
require.NoError(t, err) | ||
ts, err := EC.GetParent(ctx, head.Key()) | ||
require.NoError(t, err) | ||
require.NotEqual(t, head, ts) | ||
fmt.Printf("GetParent: %s\n", ts) | ||
} | ||
|
||
func TestGetPowerTable(t *testing.T) { | ||
head, err := EC.GetHead(ctx) | ||
require.NoError(t, err) | ||
pt, err := EC.GetPowerTable(ctx, head.Key()) | ||
require.NoError(t, err) | ||
ptJsonBytes, err := json.Marshal(&pt) | ||
require.NoError(t, err) | ||
fmt.Printf("GetPowerTable: %s\n", string(ptJsonBytes)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module f3-sidecar/v2 | ||
|
||
go 1.21 | ||
|
||
require ( | ||
github.com/filecoin-project/go-f3 v0.2.0 | ||
github.com/filecoin-project/go-jsonrpc v0.6.0 | ||
github.com/stretchr/testify v1.9.0 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/filecoin-project/go-bitfield v0.2.4 // indirect | ||
github.com/filecoin-project/go-clock v0.1.0 // indirect | ||
github.com/filecoin-project/go-state-types v0.14.0 // indirect | ||
github.com/go-logr/logr v1.4.2 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/gorilla/websocket v1.5.1 // indirect | ||
github.com/ipfs/go-cid v0.4.1 // indirect | ||
github.com/ipfs/go-log/v2 v2.5.1 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/minio/sha256-simd v1.0.1 // indirect | ||
github.com/mr-tron/base58 v1.2.0 // indirect | ||
github.com/multiformats/go-base32 v0.1.0 // indirect | ||
github.com/multiformats/go-base36 v0.2.0 // indirect | ||
github.com/multiformats/go-multibase v0.2.0 // indirect | ||
github.com/multiformats/go-multihash v0.2.3 // indirect | ||
github.com/multiformats/go-varint v0.0.7 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/spaolacci/murmur3 v1.1.0 // indirect | ||
github.com/whyrusleeping/cbor-gen v0.1.1 // indirect | ||
go.opencensus.io v0.22.3 // indirect | ||
go.opentelemetry.io/otel v1.28.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.28.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.28.0 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
go.uber.org/zap v1.27.0 // indirect | ||
golang.org/x/crypto v0.24.0 // indirect | ||
golang.org/x/net v0.26.0 // indirect | ||
golang.org/x/sys v0.21.0 // indirect | ||
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
lukechampine.com/blake3 v1.2.1 // indirect | ||
) |
Oops, something went wrong.