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

lib/runtime: use __heap_base as allocator offset #1406

Merged
merged 93 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 89 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
154d98a
life core_version call working
noot Feb 4, 2021
7caae01
add block build test for life
noot Feb 4, 2021
1f5c0dd
life instance satisfies runtime.Instance
noot Feb 4, 2021
2a7b2ff
fix runtime bug
noot Feb 5, 2021
0d7ead2
cleanup
noot Feb 5, 2021
320b962
lint
noot Feb 5, 2021
9a993f4
cleanup
noot Feb 5, 2021
5425c2b
cleanup, remove db usage in TrieState
noot Feb 5, 2021
2d93ba3
fix tests
noot Feb 5, 2021
fa3c12a
cleanup
noot Feb 5, 2021
5913e46
slightly change batch verify ordering
noot Feb 5, 2021
04da0f1
fix race test
noot Feb 5, 2021
3516ed7
add small delay after starting batch verify
noot Feb 5, 2021
577c746
fix state race
noot Feb 5, 2021
164baac
address comments
noot Feb 9, 2021
f672bf6
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Feb 9, 2021
8e6257f
merge with development
noot Feb 9, 2021
2361b39
merge with development
noot Feb 9, 2021
09bf973
fix merge errs
noot Feb 9, 2021
8a6a924
merge with development
noot Feb 10, 2021
cee10df
go mod tidy
noot Feb 10, 2021
4b29e52
randomly select peers
noot Feb 10, 2021
9d50aa1
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Feb 10, 2021
2d378dd
beginning syncQueue
noot Feb 10, 2021
10bb40d
queue functional, need to remove duplicates
noot Feb 11, 2021
8aeebed
queue functional, add checks to see if request/response is duplicate
noot Feb 11, 2021
3b259bf
fix unit tests
noot Feb 11, 2021
64684c6
fix rpc test
noot Feb 11, 2021
3bf4d83
lint
noot Feb 11, 2021
c083e39
cleanup
noot Feb 11, 2021
6ce9a2b
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Feb 11, 2021
a054786
more cleanup
noot Feb 11, 2021
4b7890b
add some tests
noot Feb 12, 2021
1c9beed
add a few more unit tests
noot Feb 12, 2021
ce37154
fix test
noot Feb 12, 2021
8acdf98
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Feb 12, 2021
577be28
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Feb 16, 2021
b52f77e
use Snapshot
noot Feb 16, 2021
8595a17
move request creation,benchmarker to network sync queue
noot Feb 16, 2021
cd925ea
fix block response filtering
noot Feb 16, 2021
7d5698f
queue semi-functional
noot Feb 17, 2021
e380bea
ensure that resposne is received before moving to next request
noot Feb 17, 2021
30cb648
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Feb 17, 2021
5940da1
queue seems mostly function except we stop getting replies after a while
noot Feb 17, 2021
dd40ae6
add max msg length fix; gossip to 1/3 of peers randomly
noot Feb 17, 2021
5119f57
network tests working
noot Feb 17, 2021
3f1c9e5
dot/sync tests ok
noot Feb 17, 2021
0be3aa0
cleanup dot/sync
noot Feb 17, 2021
4c9a261
lint, tests ok
noot Feb 17, 2021
0decfb4
add go.mod
noot Feb 17, 2021
40cbad0
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Feb 17, 2021
c63d5c8
cleanup
noot Feb 17, 2021
3fa0f99
fix network msg discard
noot Feb 17, 2021
5aaaa7e
add unit tests
noot Feb 17, 2021
21e7f18
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Feb 17, 2021
ccec623
increase max message size
noot Feb 17, 2021
2095ad0
fix test
noot Feb 18, 2021
308c333
close sync stream after sending/receiving response
noot Feb 18, 2021
b34f069
add closeStream to unsetSyncingPeer
noot Feb 18, 2021
1c8d170
fix test
noot Feb 18, 2021
6eb0f85
add licenses
noot Feb 18, 2021
cd63595
cleanup
noot Feb 18, 2021
b2cbec5
Merge branch 'development' into noot/sync-queue
noot Feb 18, 2021
d5f6cf1
read from sync stream directly aftering sending request; only allocat…
noot Feb 19, 2021
ea200a3
lint
noot Feb 19, 2021
7319e8a
add runtime.Memory.Grow, fix some tests
noot Feb 19, 2021
13328e5
lint
noot Feb 19, 2021
21744fc
cleanup
noot Feb 19, 2021
e3a735c
Merge branch 'development' into noot/sync-queue
noot Feb 19, 2021
7f31f45
merge
noot Feb 19, 2021
394c8a8
merge with development
noot Feb 19, 2021
13391fb
remove runtime changes for now
noot Feb 19, 2021
5024060
use snapshot
noot Feb 19, 2021
c9a9a26
re-add runtime files from development
noot Feb 19, 2021
2ce4714
fix network tests
noot Feb 19, 2021
a11f96d
cleanup host.send
noot Feb 19, 2021
f464698
update message handler to accept stream
noot Feb 19, 2021
bad9c1a
lint
noot Feb 19, 2021
e10a57b
cleanup
noot Feb 19, 2021
6bb224e
update wasmer to use heap base
noot Feb 22, 2021
e1326c4
cleanup
noot Feb 22, 2021
0a863b9
cleanup
noot Feb 22, 2021
a989b0d
merge
noot Feb 22, 2021
42f2b31
fix allocator test
noot Feb 22, 2021
74e1586
lint
noot Feb 22, 2021
74655e4
lint
noot Feb 22, 2021
b930f7d
cleanup
noot Feb 22, 2021
a4a767e
update DefaultHeapBase to be node_runtime __heap_base
noot Feb 22, 2021
d1b9063
cleanup
noot Feb 22, 2021
efcc25b
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Feb 23, 2021
25ecb43
cleanup
noot Feb 23, 2021
eeac5e4
maybe lint?
noot Feb 23, 2021
0c4395a
go fmt
noot Feb 23, 2021
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
4 changes: 2 additions & 2 deletions dot/network/block_announce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func TestHandleBlockAnnounceMessage(t *testing.T) {
Number: big.NewInt(10),
}

s.handleBlockAnnounceMessage(peerID, msg)
require.NotNil(t, s.syncQueue.isSyncing(peerID))
err := s.handleBlockAnnounceMessage(peerID, msg)
require.NoError(t, err)
}

func TestValidateBlockAnnounceHandshake(t *testing.T) {
Expand Down
51 changes: 25 additions & 26 deletions dot/network/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,33 +166,10 @@ func (h *host) bootstrap() {
// send writes the given message to the outbound message stream for the given
// peer (gets the already opened outbound message stream or opens a new one).
func (h *host) send(p peer.ID, sub protocol.ID, msg Message) (err error) {
encMsg, err := msg.Encode()
if err != nil {
return err
}

err = h.sendBytes(p, sub, encMsg)
if err != nil {
return err
}

logger.Trace(
"Sent message to peer",
"sub-protocol", sub,
"host", h.id(),
"peer", p,
"message", msg.String(),
)

return nil
}

func (h *host) sendBytes(p peer.ID, sub protocol.ID, msg []byte) (err error) {
// get outbound stream for given peer
s := h.getStream(p, sub)

// check if stream needs to be opened
// TODO: if stream has not been opened, begin handler for the newly opened stream
if s == nil {
logger.Debug("opening new stream with peer", "peer", p, "sub-protocol", sub)

Expand All @@ -211,11 +188,33 @@ func (h *host) sendBytes(p peer.ID, sub protocol.ID, msg []byte) (err error) {
)
}

msgLen := uint64(len(msg))
err = h.writeToStream(s, msg)
if err != nil {
return err
}

logger.Trace(
"Sent message to peer",
"sub-protocol", sub,
"host", h.id(),
"peer", p,
"message", msg.String(),
)

return nil
}

func (h *host) writeToStream(s libp2pnetwork.Stream, msg Message) error {
encMsg, err := msg.Encode()
if err != nil {
return err
}

msgLen := uint64(len(encMsg))
lenBytes := uint64ToLEB128(msgLen)
msg = append(lenBytes, msg...)
encMsg = append(lenBytes, encMsg...)

_, err = s.Write(msg)
_, err = s.Write(encMsg)
return err
}

Expand Down
58 changes: 0 additions & 58 deletions dot/network/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,70 +23,12 @@ import (
"time"

"github.com/ChainSafe/gossamer/lib/utils"
log "github.com/ChainSafe/log15"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-kad-dht/dual"
kbucket "github.com/libp2p/go-libp2p-kbucket"
"github.com/stretchr/testify/require"
)

func TestMessageSize(t *testing.T) {
size := 100000
msg := make([]byte, size)
msg[0] = 77

nodes := make([]*Service, 2)
errs := make([]chan error, 2)

for i := range nodes {
errCh := make(chan error)

config := &Config{
Port: 7000 + uint32(i),
RandSeed: 1 + int64(i),
NoBootstrap: true,
NoMDNS: true,
ErrChan: errCh,
LogLvl: log.LvlTrace,
}
node := createTestService(t, config)
defer node.Stop()
nodes[i] = node
errs[i] = errCh
handler := newTestStreamHandler(testBlockRequestMessageDecoder)
node.host.registerStreamHandler("", handler.handleStream)
}

addrs := nodes[0].host.multiaddrs()
ainfo, err := peer.AddrInfoFromP2pAddr(addrs[1])
require.NoError(t, err)

for i, n := range nodes {
if i == 0 {
// connect other nodes to first node
continue
}

err = n.host.connect(*ainfo)
require.NoError(t, err, i)
}

err = nodes[0].host.sendBytes(nodes[1].host.id(), "", msg)
require.NoError(t, err)
time.Sleep(time.Second)
err = nodes[1].host.sendBytes(nodes[0].host.id(), "", msg)
require.NoError(t, err)
time.Sleep(time.Second)

select {
case err := <-errs[0]:
t.Fatal("got error", err)
case err := <-errs[1]:
t.Fatal("got error", err)
case <-time.After(time.Millisecond * 100):
}
}

// test host connect method
func TestConnect(t *testing.T) {
basePathA := utils.NewTestBasePath(t, "nodeA")
Expand Down
11 changes: 5 additions & 6 deletions dot/network/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/common/optional"
"github.com/ChainSafe/gossamer/lib/scale"
"github.com/libp2p/go-libp2p-core/peer"
)

// Pair is a pair of arbitrary bytes.
Expand Down Expand Up @@ -263,18 +262,18 @@ func (rh *RemoteHeaderResponse) String() string {
return fmt.Sprintf("Header =%s Proof =%s", rh.Header, string(rh.proof))
}

func remoteCallResp(peer peer.ID, req *RemoteCallRequest) (*RemoteCallResponse, error) {
func remoteCallResp(req *RemoteCallRequest) (*RemoteCallResponse, error) {
return &RemoteCallResponse{}, nil
}
func remoteChangeResp(peer peer.ID, req *RemoteChangesRequest) (*RemoteChangesResponse, error) {
func remoteChangeResp(req *RemoteChangesRequest) (*RemoteChangesResponse, error) {
return &RemoteChangesResponse{}, nil
}
func remoteHeaderResp(peer peer.ID, req *RemoteHeaderRequest) (*RemoteHeaderResponse, error) {
func remoteHeaderResp(req *RemoteHeaderRequest) (*RemoteHeaderResponse, error) {
return &RemoteHeaderResponse{}, nil
}
func remoteReadChildResp(peer peer.ID, req *RemoteReadChildRequest) (*RemoteReadResponse, error) {
func remoteReadChildResp(req *RemoteReadChildRequest) (*RemoteReadResponse, error) {
return &RemoteReadResponse{}, nil
}
func remoteReadResp(peer peer.ID, req *RemoteReadRequest) (*RemoteReadResponse, error) {
func remoteReadResp(req *RemoteReadRequest) (*RemoteReadResponse, error) {
return &RemoteReadResponse{}, nil
}
41 changes: 30 additions & 11 deletions dot/network/light_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package network

import (
"testing"
"time"

"github.com/ChainSafe/gossamer/lib/utils"
"github.com/libp2p/go-libp2p-core/peer"
Expand Down Expand Up @@ -45,23 +46,41 @@ func TestDecodeLightMessage(t *testing.T) {
}

func TestHandleLightMessage_Response(t *testing.T) {
basePath := utils.NewTestBasePath(t, "nodeA")
defer utils.RemoveTestDir(t)

config := &Config{
BasePath: basePath,
BasePath: utils.NewTestBasePath(t, "nodeA"),
Port: 7001,
RandSeed: 1,
NoBootstrap: true,
NoMDNS: true,
}
s := createTestService(t, config)

peerID := peer.ID("noot")
configB := &Config{
BasePath: utils.NewTestBasePath(t, "nodeB"),
Port: 7002,
RandSeed: 2,
NoBootstrap: true,
NoMDNS: true,
}
b := createTestService(t, configB)

addrInfosB, err := b.host.addrInfos()
require.NoError(t, err)

err = s.host.connect(*addrInfosB[0])
// retry connect if "failed to dial" error
if failedToDial(err) {
time.Sleep(TestBackoffTimeout)
err = s.host.connect(*addrInfosB[0])
}
require.NoError(t, err)

stream, err := s.host.h.NewStream(s.ctx, b.host.id(), s.host.protocolID+lightID)
require.NoError(t, err)

// Testing empty request
msg := &LightRequest{}
err := s.handleLightMsg(peerID, msg)
err = s.handleLightMsg(stream, msg)
require.NoError(t, err)

expectedErr := "failed to find any peer in table"
Expand All @@ -70,34 +89,34 @@ func TestHandleLightMessage_Response(t *testing.T) {
msg = &LightRequest{
RmtCallRequest: &RemoteCallRequest{},
}
err = s.handleLightMsg(peerID, msg)
err = s.handleLightMsg(stream, msg)
require.Error(t, err, expectedErr, msg.String())

// Testing remoteHeaderResp()
msg = &LightRequest{
RmtHeaderRequest: &RemoteHeaderRequest{},
}
err = s.handleLightMsg(peerID, msg)
err = s.handleLightMsg(stream, msg)
require.Error(t, err, expectedErr, msg.String())

// Testing remoteChangeResp()
msg = &LightRequest{
RmtChangesRequest: &RemoteChangesRequest{},
}
err = s.handleLightMsg(peerID, msg)
err = s.handleLightMsg(stream, msg)
require.Error(t, err, expectedErr, msg.String())

// Testing remoteReadResp()
msg = &LightRequest{
RmtReadRequest: &RemoteReadRequest{},
}
err = s.handleLightMsg(peerID, msg)
err = s.handleLightMsg(stream, msg)
require.Error(t, err, expectedErr, msg.String())

// Testing remoteReadChildResp()
msg = &LightRequest{
RmtReadChildRequest: &RemoteReadChildRequest{},
}
err = s.handleLightMsg(peerID, msg)
err = s.handleLightMsg(stream, msg)
require.Error(t, err, expectedErr, msg.String())
}
2 changes: 1 addition & 1 deletion dot/network/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (bm *BlockRequestMessage) Decode(in []byte) error {
case *pb.BlockRequest_Number:
startingBlock, err = variadic.NewUint64OrHash(binary.LittleEndian.Uint64(from.Number))
default:
err = errors.New("invalid FromBlock")
err = errors.New("invalid StartingBlock")
}

if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions dot/network/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"math/rand"
"sync"

libp2pnetwork "github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/protocol"
)
Expand Down Expand Up @@ -80,14 +81,15 @@ func createDecoder(info *notificationsProtocol, handshakeDecoder HandshakeDecode
}

func (s *Service) createNotificationsMessageHandler(info *notificationsProtocol, handshakeValidator HandshakeValidator, messageHandler NotificationsMessageHandler) messageHandler {
return func(peer peer.ID, m Message) error {
return func(stream libp2pnetwork.Stream, m Message) error {
if m == nil || info == nil || handshakeValidator == nil || messageHandler == nil {
return nil
}

var (
ok bool
msg NotificationsMessage
ok bool
msg NotificationsMessage
peer = stream.Conn().RemotePeer()
)

if msg, ok = m.(NotificationsMessage); !ok {
Expand Down
35 changes: 20 additions & 15 deletions dot/network/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ func TestCreateNotificationsMessageHandler_BlockAnnounce(t *testing.T) {
}
require.NoError(t, err)

stream, err := s.host.h.NewStream(s.ctx, b.host.id(), s.host.protocolID+blockAnnounceID)
require.NoError(t, err)

// create info and handler
info := &notificationsProtocol{
subProtocol: blockAnnounceID,
Expand All @@ -148,9 +151,8 @@ func TestCreateNotificationsMessageHandler_BlockAnnounce(t *testing.T) {
Number: big.NewInt(10),
}

err = handler(testPeerID, msg)
err = handler(stream, msg)
require.NoError(t, err)
require.NotNil(t, s.syncQueue.isSyncing(testPeerID))
}

func TestCreateNotificationsMessageHandler_BlockAnnounceHandshake(t *testing.T) {
Expand Down Expand Up @@ -185,6 +187,20 @@ func TestCreateNotificationsMessageHandler_BlockAnnounceHandshake(t *testing.T)
// don't set handshake data ie. this stream has just been opened
testPeerID := b.host.id()

// connect nodes
addrInfosB, err := b.host.addrInfos()
require.NoError(t, err)

err = s.host.connect(*addrInfosB[0])
if failedToDial(err) {
time.Sleep(TestBackoffTimeout)
err = s.host.connect(*addrInfosB[0])
}
require.NoError(t, err)

stream, err := s.host.h.NewStream(s.ctx, b.host.id(), s.host.protocolID+blockAnnounceID)
require.NoError(t, err)

// try invalid handshake
testHandshake := &BlockAnnounceHandshake{
Roles: 4,
Expand All @@ -193,22 +209,11 @@ func TestCreateNotificationsMessageHandler_BlockAnnounceHandshake(t *testing.T)
GenesisHash: common.Hash{2},
}

err := handler(testPeerID, testHandshake)
err = handler(stream, testHandshake)
require.Equal(t, errCannotValidateHandshake, err)
require.True(t, info.handshakeData[testPeerID].received)
require.False(t, info.handshakeData[testPeerID].validated)

// connect nodes
addrInfosB, err := b.host.addrInfos()
require.NoError(t, err)

err = s.host.connect(*addrInfosB[0])
if failedToDial(err) {
time.Sleep(TestBackoffTimeout)
err = s.host.connect(*addrInfosB[0])
}
require.NoError(t, err)

// try valid handshake
testHandshake = &BlockAnnounceHandshake{
Roles: 4,
Expand All @@ -217,7 +222,7 @@ func TestCreateNotificationsMessageHandler_BlockAnnounceHandshake(t *testing.T)
GenesisHash: s.blockState.GenesisHash(),
}

err = handler(testPeerID, testHandshake)
err = handler(stream, testHandshake)
require.NoError(t, err)
require.True(t, info.handshakeData[testPeerID].received)
require.True(t, info.handshakeData[testPeerID].validated)
Expand Down
Loading