Skip to content
Merged
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
12 changes: 9 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"version": "0.2.0",
"configurations": [



{
"name": "Launch Supernode",
"type": "go",
Expand All @@ -25,6 +22,15 @@
"env": {
"LOG_LEVEL": "debug" // This may vary depending on your logger
}
},
{
"name": "Run P2P Test",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}/tests/integration/p2p",
"args": ["-test.run=TestP2PBasicIntegration", "-test.v"],
"showLog": true
}
]
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/LumeraProtocol/supernode
go 1.24.1

require (
cosmossdk.io/math v1.5.3
github.com/LumeraProtocol/lumera v0.4.5
github.com/LumeraProtocol/rq-go v0.2.1
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
Expand Down Expand Up @@ -46,7 +47,6 @@ require (
cosmossdk.io/depinject v1.1.0 // indirect
cosmossdk.io/errors v1.0.2 // indirect
cosmossdk.io/log v1.5.0 // indirect
cosmossdk.io/math v1.5.3 // indirect
cosmossdk.io/store v1.1.1 // indirect
cosmossdk.io/x/tx v0.13.7 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
Expand All @@ -62,7 +62,6 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/cockroachdb/apd/v3 v3.2.1 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ cosmossdk.io/errors v1.0.2 h1:wcYiJz08HThbWxd/L4jObeLaLySopyyuUFB5w4AGpCo=
cosmossdk.io/errors v1.0.2/go.mod h1:0rjgiHkftRYPj//3DrD6y8hcm40HcPv/dR4R/4efr0k=
cosmossdk.io/log v1.5.0 h1:dVdzPJW9kMrnAYyMf1duqacoidB9uZIl+7c6z0mnq0g=
cosmossdk.io/log v1.5.0/go.mod h1:Tr46PUJjiUthlwQ+hxYtUtPn4D/oCZXAkYevBeh5+FI=
cosmossdk.io/math v1.5.1 h1:c6zo52nBRlqOeSIIQrn/zbxwcNwhaLjTMRn6e4vD7uc=
cosmossdk.io/math v1.5.1/go.mod h1:ToembcWID/wR94cucsMD+2gq6xrlBBOfWcGwC7ZdwZA=
cosmossdk.io/math v1.5.3 h1:WH6tu6Z3AUCeHbeOSHg2mt9rnoiUWVWaQ2t6Gkll96U=
cosmossdk.io/math v1.5.3/go.mod h1:uqcZv7vexnhMFJF+6zh9EWdm/+Ylyln34IvPnBauPCQ=
cosmossdk.io/store v1.1.1 h1:NA3PioJtWDVU7cHHeyvdva5J/ggyLDkyH0hGHl2804Y=
Expand Down Expand Up @@ -157,8 +155,6 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E=
github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOGr0B9pvN3Gw=
github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg=
github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4=
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
Expand Down Expand Up @@ -907,8 +903,8 @@ golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE=
golang.org/x/oauth2 v0.26.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -1059,8 +1055,6 @@ google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11
google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg=
google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec=
google.golang.org/grpc v1.72.0 h1:S7UkcVa60b5AAQTaO6ZKamFp1zMZSU0fGDK2WZLbBnM=
google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
50 changes: 35 additions & 15 deletions p2p/kademlia/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
)

const (
bootstrapRetryInterval = 10
badAddrExpiryHours = 12
bootstrapRetryInterval = 10
badAddrExpiryHours = 12
defaultSuperNodeP2PPort = 4444
)

func (s *DHT) skipBadBootstrapAddrs() {
Expand Down Expand Up @@ -46,24 +47,46 @@ func (s *DHT) parseNode(extP2P string, selfAddr string) (*Node, error) {
return nil, errors.New("configure: skip bad p2p boostrap addr")
}

addr := strings.Split(extP2P, ":")
if len(addr) != 2 {
return nil, errors.New("wrong number of field")
// Extract IP and port from the address
var ip string
var port uint16

if idx := strings.LastIndex(extP2P, ":"); idx != -1 {
ip = extP2P[:idx]
portStr := extP2P[idx+1:]

// If we have a port in the address, parse it
if portStr != "" {
portNum, err := strconv.ParseUint(portStr, 10, 16)
if err != nil {
return nil, errors.New("invalid port number")
}

// For system testing, use port+1 if SYSTEM_TEST=true
if os.Getenv("SYSTEM_TEST") == "true" {
port = uint16(portNum) + 1
log.P2P().WithField("original_port", portNum).
WithField("adjusted_port", port).
Info("Using port+1 for system testing")
} else {
// For normal P2P operation, always use the default port
port = defaultNetworkPort
}
}
} else {
// No port in the address
ip = extP2P
port = defaultNetworkPort
}
ip := addr[0]

if ip == "" {
return nil, errors.New("empty ip")
}

port, err := strconv.ParseUint(addr[1], 10, 16)
if err != nil {
return nil, errors.New("invalid port number")
}

// Create the node with the correct IP and port
return &Node{
IP: ip,
Port: uint16(port),
Port: port,
}, nil
}

Expand Down Expand Up @@ -154,9 +177,6 @@ func (s *DHT) ConfigureBootstrapNodes(ctx context.Context, bootstrapNodes string

// Convert the map to a slice
for _, node := range mapNodes {
if os.Getenv("INTEGRATION_TEST") != "true" {
node.Port = node.Port + 1
}
hID, _ := utils.Blake3Hash(node.ID)
node.HashedID = hID
fmt.Println("node adding", node.String(), "hashed id", string(node.HashedID))
Expand Down
2 changes: 1 addition & 1 deletion p2p/kademlia/hashtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (

const (
// Alpha - a small number representing the degree of parallelism in network calls
Alpha = 3
Alpha = 6

// B - the size in bits of the keys used to identify nodes and store and
// retrieve data; in basic Kademlia this is 256, the length of a SHA3-256
Expand Down
31 changes: 2 additions & 29 deletions pkg/testutil/lumera.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package testutil

import (
"context"
"strconv"

"github.com/LumeraProtocol/lumera/x/action/types"
supernodeTypes "github.com/LumeraProtocol/lumera/x/supernode/types"
Expand Down Expand Up @@ -135,29 +134,7 @@ type MockSupernodeModule struct {
}

func (m *MockSupernodeModule) GetTopSuperNodesForBlock(ctx context.Context, blockHeight uint64) (*supernodeTypes.QueryGetTopSuperNodesForBlockResponse, error) {
// Create supernodes with the actual node addresses supplied in the test
supernodes := make([]*supernodeTypes.SuperNode, 0, len(m.addresses))

for i, addr := range m.addresses {
if i >= 2 { // Only use first couple for bootstrap
break
}

supernode := &supernodeTypes.SuperNode{
SupernodeAccount: addr, // Use the real account address for testing
PrevIpAddresses: []*supernodeTypes.IPAddressHistory{
{
Address: "127.0.0.1:900" + strconv.Itoa(i),
Height: 10,
},
},
}
supernodes = append(supernodes, supernode)
}

return &supernodeTypes.QueryGetTopSuperNodesForBlockResponse{
Supernodes: supernodes,
}, nil
return &supernodeTypes.QueryGetTopSuperNodesForBlockResponse{}, nil
}

func (m *MockSupernodeModule) GetSuperNode(ctx context.Context, address string) (*supernodeTypes.QueryGetSuperNodeResponse, error) {
Expand Down Expand Up @@ -202,11 +179,7 @@ func (m *MockNodeModule) Verify(accAddress string, data []byte, signature []byte

func (m *MockNodeModule) GetLatestBlock(ctx context.Context) (*cmtservice.GetLatestBlockResponse, error) {
return &cmtservice.GetLatestBlockResponse{
SdkBlock: &cmtservice.Block{
Header: cmtservice.Header{
Height: 100,
},
},
SdkBlock: &cmtservice.Block{},
}, nil
}

Expand Down
2 changes: 0 additions & 2 deletions tests/integration/p2p/p2p_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
func TestP2PBasicIntegration(t *testing.T) {
log.Println("Starting P2P test...")

os.Setenv("INTEGRATION_TEST", "true")
defer os.Unsetenv("INTEGRATION_TEST")
snkeyring.InitSDKConfig()
conn.RegisterALTSRecordProtocols()
defer conn.UnregisterALTSRecordProtocols()
Expand Down
3 changes: 2 additions & 1 deletion tests/system/e2e_cascade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func TestCascadeE2E(t *testing.T) {
// ---------------------------------------
// Constants and Configuration Parameters
// ---------------------------------------

os.Setenv("SYSTEM_TEST", "true")
defer os.Unsetenv("SYSTEM_TEST")
// Test account credentials - these values are consistent across test runs
const testMnemonic = "odor kiss switch swarm spell make planet bundle skate ozone path planet exclude butter atom ahead angle royal shuffle door prevent merry alter robust"
const expectedAddress = "lumera1em87kgrvgttrkvuamtetyaagjrhnu3vjy44at4"
Expand Down