Skip to content

#418 libp2p integration #420

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3d65852
feat: add aux attribute in channel.Params
NhoxxKienn Jan 23, 2025
2bb1a55
feat(adjudicate): gather state map switchs to gather signed states
NhoxxKienn Feb 26, 2025
8c7df65
feat(vc_test): add aux params to virtual channel test for utxo chains
NhoxxKienn Apr 2, 2025
e363289
feat(vc test): send parent ID in aux instead for utxo chains
NhoxxKienn Apr 2, 2025
0edd2b7
fix(vc test): fix aux generation in virtual channel test
NhoxxKienn Apr 2, 2025
634091b
feat(test/virtualchannel): add wait time for processing opening virtu…
NhoxxKienn Apr 10, 2025
1eb5cc3
feat: add log and proper secondary settle for virtual channel test di…
NhoxxKienn Apr 10, 2025
61bf760
feat: add additional payment channel test setup
NhoxxKienn Apr 14, 2025
15bf682
feat: add proper clean up for virtual channel optimistic test
NhoxxKienn Apr 15, 2025
4d68d28
feat: add client's handler for virtual channel test cleanup
NhoxxKienn Apr 15, 2025
17ac78d
Merge branch 'main' into nervos_ckb
NhoxxKienn Apr 24, 2025
22cdc68
refactor(lint): update and refactor golangci-lint
NhoxxKienn Apr 25, 2025
4eb64e3
feat(wire/net/libp2p): add initial package libp2p
NhoxxKienn Apr 28, 2025
fddc7a9
feat(go.mod): update go dependencies
NhoxxKienn Apr 28, 2025
eff95d6
feat(libp2p): add libp2p account, address
NhoxxKienn Apr 28, 2025
848f107
feat(libp2p): add dialer and listener
NhoxxKienn Apr 29, 2025
effbd00
feat(libp2p): add exchange addr tests
NhoxxKienn Apr 29, 2025
f5bde07
feat(wire/net): add bus test for libp2p and simple
NhoxxKienn Apr 30, 2025
14d52e5
Merge branch 'main' into 418_libp2p_integration
NhoxxKienn May 21, 2025
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
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ on:
release:

env:
go-version: 1.18
go-version: 1.23

jobs:
check-copyright:
name: Copyright
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Authors
Expand All @@ -26,20 +26,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Check vanity import
run: .scripts/check-vanity-imports.sh $GITHUB_WORKSPACE

- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ${{ env.go-version }}

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v7
with:
version: v1.45
version: v2.1

- name: Lint proto files
uses: plexsystems/protolint-action@v0.6.0
Expand Down
103 changes: 103 additions & 0 deletions .golangci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"formatters": {
"enable": [
"gofmt",
"gofumpt",
"goimports"
],
"exclusions": {
"generated": "lax",
"paths": [
"third_party$",
"builtin$",
"examples$"
]
}
},
"linters": {
"default": "all",
"disable": [
"err113",
"errorlint",
"gochecknoglobals",
"gochecknoinits",
"ireturn",
"lll",
"nlreturn",
"paralleltest",
"promlinter",
"tparallel",
"varnamelen",
"wrapcheck",
"wsl",
"testifylint",
"revive",
"recvcheck",
"prealloc",
"depguard",
"nonamedreturns",
"inamedparam",
"exhaustruct"
],
"exclusions": {
"generated": "lax",
"paths": [
"third_party$",
"builtin$",
"examples$"
],
"presets": [
"common-false-positives",
"legacy",
"std-error-handling"
],
"rules": [
{
"linters": [
"err113",
"forcetypeassert",
"funlen"
],
"path": "test"
},
{
"linters": [
"revive"
],
"path": "test",
"text": "context-as-argument"
}
]
},
"settings": {
"cyclop": {
"max-complexity": 15
},
"forbidigo": {
"forbid": [
{
"pattern": "^[Ee]quals$"
},
{
"pattern": "^print.*$"
},
{
"pattern": "fmt\\.Print.*"
}
]
},
"goheader": {
"template-path": ".scripts/copyright-notice",
"values": {
"regexp": {
"ANY_YEAR": "20(19|2\\d)"
}
}
}
}
},
"run": {
"modules-download-mode": "readonly"
},
"version": "2"
}
81 changes: 0 additions & 81 deletions .golangci.yml

This file was deleted.

10 changes: 5 additions & 5 deletions apps/payment/app_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestApp_ValidInit(t *testing.T) {
assert.Panics(func() { app.ValidInit(nil, wrongdata) }) //nolint:errcheck

data := &channel.State{Data: Data()}
assert.Nil(app.ValidInit(nil, data))
assert.NoError(app.ValidInit(nil, data))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be require.NoError?
assert.NoError doesn't panic but just returns a bool that isn't checked here.
https://github.com/stretchr/testify?tab=readme-ov-file#require-package

From a quick search it looks like we have that in a lot of places.
Recommendation/Suggestion: Keep it as it is now for this PR (bug existed before, too and this one is already big) and fix all of these in a separate PR.

}

func TestApp_ValidTransition(t *testing.T) {
Expand Down Expand Up @@ -93,9 +93,9 @@ func TestApp_ValidTransition(t *testing.T) {
test.WithBalances(asBalances(tt.from...)...),
)
numParticipants := len(tt.from[0])
for i := 0; i < numParticipants; i++ {
for i := range numParticipants {
// valid self-transition
assert.NoError(app.ValidTransition(nil, from, from, channel.Index(i)))
assert.NoError(app.ValidTransition(nil, from, from, channel.Index(i))) //nolint:gosec
}

for _, tto := range tt.tos {
Expand All @@ -104,8 +104,8 @@ func TestApp_ValidTransition(t *testing.T) {
test.WithAppData(Data()),
test.WithBalances(asBalances(tto.alloc...)...),
)
for i := 0; i < numParticipants; i++ {
err := app.ValidTransition(nil, from, to, channel.Index(i))
for i := range numParticipants {
err := app.ValidTransition(nil, from, to, channel.Index(i)) //nolint:gosec
if i == tto.valid {
assert.NoError(err)
} else {
Expand Down
3 changes: 2 additions & 1 deletion apps/payment/randomizer_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

_ "perun.network/go-perun/backend/sim" // backend init
"perun.network/go-perun/channel"
Expand All @@ -31,7 +32,7 @@ func TestRandomizer(t *testing.T) {
app := r.NewRandomApp(rng, channel.TestBackendID)
channel.RegisterApp(app)
regApp, err := channel.Resolve(app.Def())
assert.NoError(t, err)
require.NoError(t, err)
assert.True(t, app.Def().Equal(regApp.Def()))
assert.True(t, IsData(r.NewRandomData(rng)))
}
4 changes: 2 additions & 2 deletions apps/payment/resolver_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestResolver(t *testing.T) {
channel.RegisterAppResolver(def.Equal, &Resolver{})

app, err := channel.Resolve(def)
assert.NoError(err)
require.NoError(err)
require.NotNil(app)
assert.True(def.Equal(app.Def()))
}
Expand All @@ -47,7 +47,7 @@ func TestData(t *testing.T) {
assert.NotPanics(func() {
data := Data()
_, err := data.MarshalBinary()
assert.Nil(err)
assert.NoError(err)
})

assert.NotPanics(func() {
Expand Down
12 changes: 6 additions & 6 deletions backend/sim/channel/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ type AppID struct {
*wallet.Address
}

// NewRandomAppID generates a new random app identifier.
func NewRandomAppID(rng *rand.Rand) AppID {
addr := wallet.NewRandomAddress(rng)
return AppID{Address: addr}
}

// Equal returns whether the object is equal to the given object.
func (id AppID) Equal(b channel.AppID) bool {
bTyped, ok := b.(AppID)
Expand All @@ -44,9 +50,3 @@ func (id AppID) Key() channel.AppIDKey {
}
return channel.AppIDKey(b)
}

// NewRandomAppID generates a new random app identifier.
func NewRandomAppID(rng *rand.Rand) AppID {
addr := wallet.NewRandomAddress(rng)
return AppID{Address: addr}
}
13 changes: 11 additions & 2 deletions backend/sim/channel/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ package channel
import (
"encoding/binary"
"fmt"
"math"
"math/rand"

"github.com/pkg/errors"
"perun.network/go-perun/channel"
)

Expand All @@ -44,16 +46,23 @@ func NewRandomAsset(rng *rand.Rand) *Asset {
// MarshalBinary marshals the address into its binary representation.
func (a Asset) MarshalBinary() ([]byte, error) {
data := make([]byte, assetLen)
if a.ID < 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that Asset.ID is int64 instead of uint64?

If not I'd suggest to make it a uint64 (and potentially even a private field). That way we don't need any of this integer casting.

The only external user I could find was the Test_Asset_GenericMarshaler test and that only generates positive IDs, so the code for a.ID < 0 isn't tested either:

// Int63 returns a non-negative pseudo-random 63-bit integer as an int64.
func (r *Rand) Int63() int64 { return r.src.Int63() }

return nil, errors.New("asset ID must be non-negative")
}
byteOrder.PutUint64(data, uint64(a.ID))
return data, nil
}

// UnmarshalBinary unmarshals the asset from its binary representation.
func (a *Asset) UnmarshalBinary(data []byte) error {
if len(data) != assetLen {
return fmt.Errorf("unexpected length %d, want %d", len(data), assetLen) //nolint:goerr113 // We do not want to define this as constant error.
return fmt.Errorf("unexpected length %d, want %d", len(data), assetLen) // We do not want to define this as constant error.
}
id := byteOrder.Uint64(data)
if id > math.MaxInt64 {
return fmt.Errorf("asset ID %d is too large", id)
}
a.ID = int64(byteOrder.Uint64(data))
a.ID = int64(id)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion backend/sim/channel/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

func Test_Asset_GenericMarshaler(t *testing.T) {
rng := pkgtest.Prng(t)
for n := 0; n < 10; n++ {
for range 10 {
test.GenericMarshalerTest(t, &channel.Asset{ID: rng.Int63()})
}
}
Loading