Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
26c82cf
chore: remove unneeded field
EclesioMeloJunior Nov 25, 2022
c2e75e4
chore: fix .proto prettier
EclesioMeloJunior Nov 25, 2022
14651c2
chore: resolve westend-local/config-bob.toml
EclesioMeloJunior Nov 25, 2022
8121eaf
chore: fix westend-local/raw.json
EclesioMeloJunior Nov 25, 2022
6f03122
Merge branch 'development' into eclesio/remove-endblockhash
EclesioMeloJunior Nov 25, 2022
d4c8e6a
chore: make linter happy
EclesioMeloJunior Dec 5, 2022
9b29e11
chore: addressing nits
EclesioMeloJunior Dec 5, 2022
0f3b1d0
chore: update proto/pb.go files
EclesioMeloJunior Dec 5, 2022
b0ac8a9
Merge branch 'development' into eclesio/remove-endblockhash
EclesioMeloJunior Dec 5, 2022
5019994
Merge branch 'development' into eclesio/remove-endblockhash
EclesioMeloJunior Dec 5, 2022
1e8477d
chore: fix tests that rely on end hash
EclesioMeloJunior Dec 5, 2022
967707b
Merge branch 'eclesio/remove-endblockhash' of github.com:ChainSafe/go…
EclesioMeloJunior Dec 5, 2022
4edec17
chore: fix `TestEncodeBlockRequestMessage` test
EclesioMeloJunior Dec 5, 2022
1c29e47
chore: addressing comments
EclesioMeloJunior Dec 6, 2022
01834e0
chore: fix test `TestService_CreateBlockResponse_StartHash`
EclesioMeloJunior Dec 6, 2022
af5268c
chore: keep the year in the copyright
EclesioMeloJunior Dec 6, 2022
5e01e3f
chore: remove unit tests that asserts end_hash removed field
EclesioMeloJunior Dec 6, 2022
0444f86
Merge branch 'development' into eclesio/remove-endblockhash
EclesioMeloJunior Dec 6, 2022
e829d44
Merge branch 'development' into eclesio/remove-endblockhash
EclesioMeloJunior Dec 6, 2022
019b94b
Merge branch 'development' into eclesio/remove-endblockhash
EclesioMeloJunior Dec 7, 2022
59420ec
chore: add `reserved 4` to .proto file
EclesioMeloJunior Dec 7, 2022
6ea0025
chore: fix formatting adding a space between words
EclesioMeloJunior Dec 7, 2022
b108337
chore: remove the `reserved` keyword from `.proto` file
EclesioMeloJunior Dec 7, 2022
5cc4d68
chore: using the right protoc version
EclesioMeloJunior Dec 7, 2022
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: 1 addition & 3 deletions dot/network/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import (
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/common/variadic"
gomock "github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

libp2pnetwork "github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -131,7 +130,6 @@ func newTestBlockRequestMessage(t *testing.T) *BlockRequestMessage {
return &BlockRequestMessage{
RequestedData: RequestedDataHeader + RequestedDataBody + RequestedDataJustification,
StartingBlock: *starting,
EndBlockHash: &common.Hash{},
Direction: 1,
Max: &one,
}
Expand Down
31 changes: 3 additions & 28 deletions dot/network/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,48 +75,32 @@ func (sd SyncDirection) String() string {
type BlockRequestMessage struct {
RequestedData byte
StartingBlock variadic.Uint32OrHash // first byte 0 = block hash (32 byte), first byte 1 = block number (uint32)
EndBlockHash *common.Hash
Direction SyncDirection // 0 = ascending, 1 = descending
Direction SyncDirection // 0 = ascending, 1 = descending
Max *uint32
}

// String formats a BlockRequestMessage as a string
func (bm *BlockRequestMessage) String() string {
hash := common.Hash{}
max := uint32(0)
if bm.EndBlockHash != nil {
hash = *bm.EndBlockHash
}
if bm.Max != nil {
max = *bm.Max
}
return fmt.Sprintf("BlockRequestMessage RequestedData=%d StartingBlock=%v EndBlockHash=%s Direction=%d Max=%d",
return fmt.Sprintf("BlockRequestMessage RequestedData=%d StartingBlock=%v Direction=%d Max=%d",
bm.RequestedData,
bm.StartingBlock,
hash.String(),
bm.Direction,
max)
}

// Encode returns the protobuf encoded BlockRequestMessage
func (bm *BlockRequestMessage) Encode() ([]byte, error) {
var (
toBlock []byte
max uint32
)

if bm.EndBlockHash != nil {
hash := bm.EndBlockHash
toBlock = hash[:]
}

var max uint32
if bm.Max != nil {
max = *bm.Max
}

msg := &pb.BlockRequest{
Fields: uint32(bm.RequestedData) << 24, // put byte in most significant byte of uint32
ToBlock: toBlock,
Direction: pb.Direction(bm.Direction),
MaxBlocks: max,
}
Expand Down Expand Up @@ -149,7 +133,6 @@ func (bm *BlockRequestMessage) Decode(in []byte) error {

var (
startingBlock *variadic.Uint32OrHash
endBlockHash *common.Hash
max *uint32
)

Expand All @@ -171,13 +154,6 @@ func (bm *BlockRequestMessage) Decode(in []byte) error {
return err
}

if len(msg.ToBlock) != 0 {
hash := common.NewHash(msg.ToBlock)
endBlockHash = &hash
} else {
endBlockHash = nil
}

if msg.MaxBlocks != 0 {
max = &msg.MaxBlocks
} else {
Expand All @@ -186,7 +162,6 @@ func (bm *BlockRequestMessage) Decode(in []byte) error {

bm.RequestedData = byte(msg.Fields >> 24)
bm.StartingBlock = *startingBlock
bm.EndBlockHash = endBlockHash
bm.Direction = SyncDirection(byte(msg.Direction))
bm.Max = max

Expand Down
16 changes: 4 additions & 12 deletions dot/network/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,22 @@ import (
func TestEncodeBlockRequestMessage(t *testing.T) {
t.Parallel()

expected := common.MustHexToBytes("0x08808080082220fd19d9ebac759c993fd2e05a1cff9e757d8741c2704c8682c15b5503496b6aa1280130011220dcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b") //nolint:lll
expected := common.MustHexToBytes("0x0880808008280130011220dcd1346701ca8396496e52" +
"aa2785b1748deb6db09551b72159dcb3e08991025b")
genesisHash := common.MustHexToBytes("0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b")
endBlock := common.MustHexToHash("0xfd19d9ebac759c993fd2e05a1cff9e757d8741c2704c8682c15b5503496b6aa1")

var one uint32 = 1
bm := &BlockRequestMessage{
RequestedData: 1,
StartingBlock: *variadic.NewUint32OrHashFromBytes(append([]byte{0}, genesisHash...)),
EndBlockHash: &endBlock,
Direction: 1,
Max: &one,
}

encMsg, err := bm.Encode()
require.NoError(t, err)

require.Equal(t, expected, encMsg) // Pass!
require.Equal(t, expected, encMsg)

res := new(BlockRequestMessage)
err = res.Decode(encMsg)
Expand All @@ -46,13 +45,11 @@ func TestEncodeBlockRequestMessage_BlockHash(t *testing.T) {
t.Parallel()

genesisHash := common.MustHexToBytes("0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b")
endBlock := common.MustHexToHash("0xfd19d9ebac759c993fd2e05a1cff9e757d8741c2704c8682c15b5503496b6aa1")

var one uint32 = 1
bm := &BlockRequestMessage{
RequestedData: 1,
StartingBlock: *variadic.NewUint32OrHashFromBytes(append([]byte{0}, genesisHash...)),
EndBlockHash: &endBlock,
Direction: 1,
Max: &one,
}
Expand All @@ -69,13 +66,10 @@ func TestEncodeBlockRequestMessage_BlockHash(t *testing.T) {
func TestEncodeBlockRequestMessage_BlockNumber(t *testing.T) {
t.Parallel()

endBlock := common.MustHexToHash("0xfd19d9ebac759c993fd2e05a1cff9e757d8741c2704c8682c15b5503496b6aa1")

var one uint32 = 1
bm := &BlockRequestMessage{
RequestedData: 1,
StartingBlock: *variadic.NewUint32OrHashFromBytes([]byte{1, 1}),
EndBlockHash: &endBlock,
Direction: 1,
Max: &one,
}
Expand All @@ -97,13 +91,12 @@ func TestBlockRequestString(t *testing.T) {
bm := &BlockRequestMessage{
RequestedData: 1,
StartingBlock: *variadic.NewUint32OrHashFromBytes(append([]byte{0}, genesisHash...)),
EndBlockHash: nil,
Direction: 1,
Max: nil,
}

var blockRequestStringRegex = regexp.MustCompile(
`^\ABlockRequestMessage RequestedData=[0-9]* StartingBlock={[\[0-9(\s?)]+\]} EndBlockHash=0x[0-9]+ Direction=[0-9]* Max=[0-9]*\z$`) //nolint:lll
`^\ABlockRequestMessage RequestedData=[0-9]* StartingBlock={[\[0-9(\s?)]+\]} Direction=[0-9]* Max=[0-9]*\z$`) //nolint:lll

match := blockRequestStringRegex.MatchString(bm.String())
require.True(t, match)
Expand All @@ -117,7 +110,6 @@ func TestEncodeBlockRequestMessage_NoOptionals(t *testing.T) {
bm := &BlockRequestMessage{
RequestedData: 1,
StartingBlock: *variadic.NewUint32OrHashFromBytes(append([]byte{0}, genesisHash...)),
EndBlockHash: nil,
Direction: 1,
Max: nil,
}
Expand Down
86 changes: 38 additions & 48 deletions dot/network/proto/api.v1.pb.go

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

2 changes: 0 additions & 2 deletions dot/network/proto/api.v1.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ message BlockRequest {
// Start with given block number.
bytes number = 3;
}
// End at this block. An implementation defined maximum is used when unspecified.
bytes to_block = 4; // optional
// Sequence direction.
Direction direction = 5;
// Maximum number of blocks to return. An implementation defined maximum is used when unspecified.
Expand Down
8 changes: 0 additions & 8 deletions dot/sync/chain_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,17 +1038,9 @@ func workerToRequests(w *worker) ([]*network.BlockRequestMessage, error) {
}
}

var end *common.Hash
if !w.targetHash.IsEmpty() && i == numRequests-1 {
// if we're on our last request (which should contain the target hash),
// then add it
end = &w.targetHash
}

reqs[i] = &network.BlockRequestMessage{
RequestedData: w.requestData,
StartingBlock: *start,
EndBlockHash: end,
Direction: w.direction,
Max: &max,
}
Expand Down
Loading