Skip to content
Closed
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
3 changes: 2 additions & 1 deletion cmd/f3/aider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/filecoin-project/go-f3/internal/psutil"
"github.com/filecoin-project/go-f3/manifest"
"github.com/filecoin-project/go-f3/observer"
"github.com/filecoin-project/go-f3/pmsg"
"github.com/libp2p/go-libp2p"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/p2p/net/connmgr"
Expand Down Expand Up @@ -229,7 +230,7 @@ func aid(c *cli.Context, f3Chatter *pubsub.Topic) error {
}
fmt.Printf("⚙️ Found %d distinct senders\n", len(senders))

msgEncoding, err := encoding.NewZSTD[*gpbft.PartialGMessage]()
msgEncoding, err := encoding.NewZSTD[*pmsg.PartialGMessage]()
if err != nil {
return fmt.Errorf("failed to create zstd message encoding: %w", err)
}
Expand Down
19 changes: 10 additions & 9 deletions encoding_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-f3/gpbft"
"github.com/filecoin-project/go-f3/internal/encoding"
"github.com/filecoin-project/go-f3/pmsg"
"github.com/ipfs/go-cid"
"github.com/multiformats/go-multihash"
"github.com/stretchr/testify/require"
Expand All @@ -16,7 +17,7 @@ const seed = 1413

func BenchmarkCborEncoding(b *testing.B) {
rng := rand.New(rand.NewSource(seed))
encoder := encoding.NewCBOR[*gpbft.PartialGMessage]()
encoder := encoding.NewCBOR[*pmsg.PartialGMessage]()
msg := generateRandomPartialGMessage(b, rng)

b.ResetTimer()
Expand All @@ -32,7 +33,7 @@ func BenchmarkCborEncoding(b *testing.B) {

func BenchmarkCborDecoding(b *testing.B) {
rng := rand.New(rand.NewSource(seed))
encoder := encoding.NewCBOR[*gpbft.PartialGMessage]()
encoder := encoding.NewCBOR[*pmsg.PartialGMessage]()
msg := generateRandomPartialGMessage(b, rng)
data, err := encoder.Encode(msg)
require.NoError(b, err)
Expand All @@ -41,7 +42,7 @@ func BenchmarkCborDecoding(b *testing.B) {
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
var got gpbft.PartialGMessage
var got pmsg.PartialGMessage
require.NoError(b, encoder.Decode(data, &got))
requireEqualPartialMessages(b, msg, &got)
}
Expand All @@ -50,7 +51,7 @@ func BenchmarkCborDecoding(b *testing.B) {

func BenchmarkZstdEncoding(b *testing.B) {
rng := rand.New(rand.NewSource(seed))
encoder, err := encoding.NewZSTD[*gpbft.PartialGMessage]()
encoder, err := encoding.NewZSTD[*pmsg.PartialGMessage]()
require.NoError(b, err)
msg := generateRandomPartialGMessage(b, rng)

Expand All @@ -67,7 +68,7 @@ func BenchmarkZstdEncoding(b *testing.B) {

func BenchmarkZstdDecoding(b *testing.B) {
rng := rand.New(rand.NewSource(seed))
encoder, err := encoding.NewZSTD[*gpbft.PartialGMessage]()
encoder, err := encoding.NewZSTD[*pmsg.PartialGMessage]()
require.NoError(b, err)
msg := generateRandomPartialGMessage(b, rng)
data, err := encoder.Encode(msg)
Expand All @@ -77,14 +78,14 @@ func BenchmarkZstdDecoding(b *testing.B) {
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
var got gpbft.PartialGMessage
var got pmsg.PartialGMessage
require.NoError(b, encoder.Decode(data, &got))
requireEqualPartialMessages(b, msg, &got)
}
})
}

func requireEqualPartialMessages(b *testing.B, expected, actual *gpbft.PartialGMessage) {
func requireEqualPartialMessages(b *testing.B, expected, actual *pmsg.PartialGMessage) {
// Because empty ECChain gets marshaled as null, we need to use ECChain.Eq for
// checking equality. Hence, the custom equality check.
require.Equal(b, expected.Sender, actual.Sender)
Expand All @@ -102,8 +103,8 @@ func requireEqualPartialMessages(b *testing.B, expected, actual *gpbft.PartialGM
}
}

func generateRandomPartialGMessage(b *testing.B, rng *rand.Rand) *gpbft.PartialGMessage {
var pgmsg gpbft.PartialGMessage
func generateRandomPartialGMessage(b *testing.B, rng *rand.Rand) *pmsg.PartialGMessage {
var pgmsg pmsg.PartialGMessage
pgmsg.GMessage = generateRandomGMessage(b, rng)
pgmsg.GMessage.Vote.Value = nil
if pgmsg.Justification != nil {
Expand Down
7 changes: 6 additions & 1 deletion gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/filecoin-project/go-f3/certs"
"github.com/filecoin-project/go-f3/chainexchange"
"github.com/filecoin-project/go-f3/gpbft"
"github.com/filecoin-project/go-f3/pmsg"
gen "github.com/whyrusleeping/cbor-gen"
"golang.org/x/sync/errgroup"
)
Expand All @@ -21,7 +22,6 @@ func main() {
gpbft.TipSet{},
gpbft.LegacyECChain{},
gpbft.GMessage{},
gpbft.PartialGMessage{},
gpbft.SupplementalData{},
gpbft.Payload{},
gpbft.Justification{},
Expand All @@ -47,6 +47,11 @@ func main() {
chainexchange.Message{},
)
})
eg.Go(func() error {
return gen.WriteTupleEncodersToFile("../pmsg/cbor_gen.go", "pmsg",
pmsg.PartialGMessage{},
)
})
if err := eg.Wait(); err != nil {
fmt.Printf("Failed to complete cborg_gen: %v\n", err)
os.Exit(1)
Expand Down
10 changes: 0 additions & 10 deletions gpbft/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ type ValidatedMessage interface {
Message() *GMessage
}

type PartialMessageValidator interface {
PartiallyValidateMessage(ctx context.Context, msg *PartialGMessage) (PartiallyValidatedMessage, error)
FullyValidateMessage(ctx context.Context, msg PartiallyValidatedMessage) (ValidatedMessage, error)
}

type PartiallyValidatedMessage interface {
// Returns the partially validated message.
PartialMessage() *PartialGMessage
}

// Receives a Granite protocol message.
// Calls to methods on this interface are expected to be serialized.
// The methods are not safe for concurrent use, and may panic if called concurrently.
Expand Down
100 changes: 0 additions & 100 deletions gpbft/cbor_gen.go

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

22 changes: 1 addition & 21 deletions gpbft/errors.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package gpbft

import (
"errors"
"fmt"
"runtime/debug"
)
import "errors"

var (
_ error = (*ValidationError)(nil)
Expand Down Expand Up @@ -44,21 +40,5 @@ var (
// ValidationError signals that an error has occurred while validating a GMessage.
type ValidationError struct{ message string }

type PanicError struct {
Cause any
stackTrace string
}

func newValidationError(message string) ValidationError { return ValidationError{message: message} }
func (e ValidationError) Error() string { return e.message }

func newPanicError(cause any) *PanicError {
return &PanicError{
Cause: cause,
stackTrace: string(debug.Stack()),
}
}

func (e *PanicError) Error() string {
return fmt.Sprintf("participant panicked: %v\n%v", e.Cause, e.stackTrace)
}
Loading
Loading