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

feat(parachain): Implement request and response message for /req_statement/1 protocol #3354

Merged
merged 34 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a556c9e
feat/scale: add `BitVec` (#3253)
kanishkatn May 29, 2023
78b00f9
Merge branch 'development' into feat/parachain
kanishkatn May 30, 2023
9898735
Merge branch 'development' into feat/parachain
kanishkatn Jun 5, 2023
2d57d59
Merge branch 'development' into feat/parachain
kanishkatn Jun 7, 2023
1782a1b
feat(erasure_coding): introduce erasure coding for PoV Distributor (#…
edwardmack Jun 8, 2023
05160a2
chore(deps): bump github.com/go-playground/validator/v10 from 10.14.0…
dependabot[bot] Jun 7, 2023
17a0168
chore(lib/runtime): revise `lib/runtime` interfaces (#3290)
timwu20 Jun 7, 2023
5c5720c
chore(deps): bump github.com/stretchr/testify from 1.8.3 to 1.8.4 (#3…
dependabot[bot] Jun 7, 2023
fba1036
feat(lib/blocktree): reduce the entries in the runtimes mapping (#3151)
EclesioMeloJunior Jun 7, 2023
8e67ce5
Merge branch 'development' into feat/parachain
kanishkatn Jun 9, 2023
26770e7
Fix(lint): fixes a lint issue in bitvec-test (#3306)
kanishkatn Jun 9, 2023
9a7b632
feat(parachain): add types (#3297)
kanishkatn Jun 15, 2023
1f4b871
feat(parachain): Add StatementDistributionMessage varingDataType (#3316)
axaysagathiya Jun 20, 2023
d18af54
update `feat/parachain` with `development` (#3345)
kishansagathiya Jun 20, 2023
f7820dd
feat/runtime: Add few parachain runtime calls (#3241)
kanishkatn Jun 21, 2023
aa21d8b
implement statement fetching request and response
axaysagathiya Jun 21, 2023
010f0b1
improve comments
axaysagathiya Jun 21, 2023
6a6480e
feat(parachain): Create struct for Approval Distribution Message (#3326)
edwardmack Jun 21, 2023
49c375b
combine request and response file and add tests
axaysagathiya Jun 22, 2023
08501a3
clean up
axaysagathiya Jun 22, 2023
dd26d6c
Merge branch 'feat/parachain' of github.com:ChainSafe/gossamer into i…
axaysagathiya Jun 23, 2023
36998b3
lint
axaysagathiya Jun 23, 2023
0712732
lint
axaysagathiya Jun 23, 2023
298ecd4
lint
axaysagathiya Jun 23, 2023
bff52ae
chore(parachain): improve comments of statement and statement distrib…
axaysagathiya Jun 23, 2023
c3bd831
feat(parachain): Add CollationProtocol VaryingDataType (#3337)
axaysagathiya Jun 26, 2023
3cc48bc
improve test
axaysagathiya Jun 28, 2023
2dcb50f
clean up
axaysagathiya Jun 28, 2023
3faf3dd
Merge branch 'feat/parachain' of github.com:ChainSafe/gossamer into i…
axaysagathiya Jun 28, 2023
dda0f92
lint
axaysagathiya Jun 28, 2023
8d2ea62
Merge branch 'feat/parachain' into issue-3343
axaysagathiya Jul 5, 2023
9cc21dc
use realistic hash values
axaysagathiya Jul 5, 2023
ca1e3d7
improve comment
axaysagathiya Jul 5, 2023
d30feb6
add test cases
axaysagathiya Jul 5, 2023
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
2 changes: 1 addition & 1 deletion lib/parachain/collation_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestCollationProtocol(t *testing.T) {
copy(collatorID[:], tempCollatID)

var collatorSignature CollatorSignature
tempSignature := common.MustHexToBytes(testSDMHex["collatorSignature"])
tempSignature := common.MustHexToBytes(testDataStatement["collatorSignature"])
copy(collatorSignature[:], tempSignature)

var validatorSignature ValidatorSignature
Expand Down
16 changes: 8 additions & 8 deletions lib/parachain/statement_distribution_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"gopkg.in/yaml.v3"
)

//go:embed testdata/statement_distribution_message.yaml
var testSDMHexRaw string
//go:embed testdata/statement.yaml
var testDataStatementRaw string

var testSDMHex map[string]string
var testDataStatement map[string]string

func init() {
err := yaml.Unmarshal([]byte(testSDMHexRaw), &testSDMHex)
err := yaml.Unmarshal([]byte(testDataStatementRaw), &testDataStatement)
if err != nil {
fmt.Printf("Error unmarshaling test data: %s\n", err)
return
Expand All @@ -28,7 +28,7 @@ func TestStatementDistributionMessage(t *testing.T) {
t.Parallel()

var collatorSignature CollatorSignature
tempSignature := common.MustHexToBytes(testSDMHex["collatorSignature"])
tempSignature := common.MustHexToBytes(testDataStatement["collatorSignature"])
copy(collatorSignature[:], tempSignature)

var validatorSignature ValidatorSignature
Expand Down Expand Up @@ -166,17 +166,17 @@ func TestStatementDistributionMessage(t *testing.T) {
{
name: "SignedFullStatement with valid statement",
enumValue: signedFullStatementWithValid,
encodingValue: common.MustHexToBytes(testSDMHex["sfsValid"]),
encodingValue: common.MustHexToBytes(testDataStatement["sfsValid"]),
},
{
name: "SignedFullStatement with Seconded statement",
enumValue: signedFullStatementWithSeconded,
encodingValue: common.MustHexToBytes(testSDMHex["sfsSeconded"]),
encodingValue: common.MustHexToBytes(testDataStatement["sfsSeconded"]),
},
{
name: "Seconded Statement With LargePayload",
enumValue: secondedStatementWithLargePayload,
encodingValue: common.MustHexToBytes(testSDMHex["statementWithLargePayload"]),
encodingValue: common.MustHexToBytes(testDataStatement["statementWithLargePayload"]),
},
}

Expand Down
81 changes: 81 additions & 0 deletions lib/parachain/statement_fetching.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package parachain

import (
"fmt"

"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/pkg/scale"
)

// Request for fetching a large statement via request/response.
type StatementFetchingRequest struct {
// Data needed to locate and identify the needed statement.
RelayParent common.Hash `scale:"1"`

// Hash of candidate that was used create the `CommitedCandidateRecept`.
CandidateHash CandidateHash `scale:"2"`
}

// Encode returns the SCALE encoding of the StatementFetchingRequest.
func (s *StatementFetchingRequest) Encode() ([]byte, error) {
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved
return scale.Marshal(*s)
}

// StatementFetchingResponse represents the statement fetching response is
// sent by nodes to the clients who issued a collation fetching request.
//
// Respond with found full statement.
type StatementFetchingResponse scale.VaryingDataType

// MissingDataInStatement represents the data missing to reconstruct the full signed statement.
type MissingDataInStatement CommittedCandidateReceipt

// Index returns the index of varying data type
func (MissingDataInStatement) Index() uint {
return 0
}

// NewStatementFetchingResponse returns a new statement fetching response varying data type
func NewStatementFetchingResponse() StatementFetchingResponse {
vdt := scale.MustNewVaryingDataType(MissingDataInStatement{})
return StatementFetchingResponse(vdt)
}

// Set will set a value using the underlying varying data type
func (s *StatementFetchingResponse) Set(val scale.VaryingDataTypeValue) (err error) {
vdt := scale.VaryingDataType(*s)
err = vdt.Set(val)
if err != nil {
return fmt.Errorf("setting value to varying data type: %w", err)
}

*s = StatementFetchingResponse(vdt)
return nil
}

// Value returns the value from the underlying varying data type
func (s *StatementFetchingResponse) Value() (scale.VaryingDataTypeValue, error) {
vdt := scale.VaryingDataType(*s)
return vdt.Value()
}

// Encode returns the SCALE encoding of the StatementFetchingResponse.
func (s *StatementFetchingResponse) Encode() ([]byte, error) {
return scale.Marshal(*s)
}

// Decode returns the SCALE decoding of the StatementFetchingResponse.
func (s *StatementFetchingResponse) Decode(in []byte) (err error) {
return scale.Unmarshal(in, s)
}

// String formats a StatementFetchingResponse as a string
func (s *StatementFetchingResponse) String() string {
if s == nil {
return "StatementFetchingResponse=nil"
}

v, _ := s.Value()
missingData := v.(MissingDataInStatement)
return fmt.Sprintf("StatementFetchingResponse MissingDataInStatement=%+v", missingData)
}
120 changes: 120 additions & 0 deletions lib/parachain/statement_fetching_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package parachain

import (
"testing"

"github.com/ChainSafe/gossamer/lib/common"
"github.com/stretchr/testify/require"
)

func TestEncodeStatementFetchingRequest(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
request StatementFetchingRequest
expectedEncode []byte
}{
{
// expected encoding is generated by running rust test code:
// fn statement_request() {
// let hash4 = Hash::repeat_byte(4);
// let statement_fetching_request = StatementFetchingRequest{
// relay_parent: hash4,
// candidate_hash: CandidateHash(hash4)
// };
// println!(
// "statement_fetching_request encode => {:?}\n\n",
// statement_fetching_request.encode()
// );
// }
name: "all_4_in_hash",
request: StatementFetchingRequest{
RelayParent: getDummyHash(4),
CandidateHash: CandidateHash{Value: getDummyHash(4)},
},
expectedEncode: common.MustHexToBytes(testDataStatement["all4InCommonHash"]),
},
{
name: "all_7_in_hash",
request: StatementFetchingRequest{
RelayParent: getDummyHash(7),
CandidateHash: CandidateHash{Value: getDummyHash(7)},
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved
},
expectedEncode: common.MustHexToBytes(testDataStatement["all7InCommonHash"]),
},
}

for _, c := range testCases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
actualEncode, err := c.request.Encode()
require.NoError(t, err)
require.Equal(t, c.expectedEncode, actualEncode)
})
}
}

func TestStatementFetchingResponse(t *testing.T) {
t.Parallel()

hash5 := getDummyHash(5)
axaysagathiya marked this conversation as resolved.
Show resolved Hide resolved

var collatorID CollatorID
tempCollatID := common.MustHexToBytes("0x48215b9d322601e5b1a95164cea0dc4626f545f98343d07f1551eb9543c4b147")
copy(collatorID[:], tempCollatID)

var collatorSignature CollatorSignature
tempSignature := common.MustHexToBytes(testDataStatement["collatorSignature"])
copy(collatorSignature[:], tempSignature)

missingDataInStatement := MissingDataInStatement{
Descriptor: CandidateDescriptor{
ParaID: uint32(1),
RelayParent: hash5,
Collator: collatorID,
PersistedValidationDataHash: hash5,
PovHash: hash5,
ErasureRoot: hash5,
Signature: collatorSignature,
ParaHead: hash5,
ValidationCodeHash: ValidationCodeHash(hash5),
},
Commitments: CandidateCommitments{
UpwardMessages: []UpwardMessage{{1, 2, 3}},
NewValidationCode: &ValidationCode{1, 2, 3},
HeadData: headData{1, 2, 3},
ProcessedDownwardMessages: uint32(5),
HrmpWatermark: uint32(0),
},
}

EncodedValue := common.MustHexToBytes(testDataStatement["hexOfStatementFetchingResponse"])

t.Run("encode_statement_fetching_response", func(t *testing.T) {
t.Parallel()

response := NewStatementFetchingResponse()
err := response.Set(missingDataInStatement)
require.NoError(t, err)

actualEncode, err := response.Encode()
require.NoError(t, err)

require.Equal(t, EncodedValue, actualEncode)
})

t.Run("Decode_statement_fetching_response", func(t *testing.T) {
t.Parallel()

response := NewStatementFetchingResponse()
err := response.Decode(EncodedValue)
require.NoError(t, err)

actualData, err := response.Value()
require.NoError(t, err)

require.EqualValues(t, missingDataInStatement, actualData)
})
}
5 changes: 2 additions & 3 deletions lib/parachain/statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestStatement(t *testing.T) {
copy(collatorID[:], tempCollatID)

var collatorSignature CollatorSignature
tempSignature := common.MustHexToBytes(testSDMHex["collatorSignature"])
tempSignature := common.MustHexToBytes(testDataStatement["collatorSignature"])
copy(collatorSignature[:], tempSignature)

hash5 := getDummyHash(5)
Expand Down Expand Up @@ -59,8 +59,7 @@ func TestStatement(t *testing.T) {
{
name: "Seconded",
enumValue: secondedEnumValue,
encodingValue: common.MustHexToBytes(testSDMHex["statementSeconded"]),
// expected Hex stored in statement_distribution_message.yaml
encodingValue: common.MustHexToBytes(testDataStatement["statementSeconded"]),
},
{
name: "Valid",
Expand Down
31 changes: 31 additions & 0 deletions lib/parachain/testdata/statement.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

# ==========| statement distribution message |==========


collatorSignature: "0xc67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b86"

# Seconded
statementSeconded: "0x0101000000050505050505050505050505050505050505050505050505050505050505050548215b9d322601e5b1a95164cea0dc4626f545f98343d07f1551eb9543c4b147050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505c67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b8605050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505040c01020300010c0102030c0102030500000000000000"

# SignedFullStatement with valid statement
sfsValid: "0x00050505050505050505050505050505050505050505050505050505050505050502050505050505050505050505050505050505050505050505050505050505050505000000c67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b86"

# SignedFullStatement with Seconded statement
sfsSeconded: "0x0005050505050505050505050505050505050505050505050505050505050505050101000000050505050505050505050505050505050505050505050505050505050505050548215b9d322601e5b1a95164cea0dc4626f545f98343d07f1551eb9543c4b147050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505c67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b8605050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505040c01020300010c0102030c010203050000000000000005000000c67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b86"

# Seconded Statement With LargePayload
statementWithLargePayload: "0x010505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505000000c67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b86"



# ==========| statement fetching request and response |==========


# hex of a common.Hash where all 32 bytes are set to 4.
all4InCommonHash: "0x04040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404"

# hex of a common.Hash where all 32 bytes are set to 7.
all7InCommonHash: "0x07070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707070707"

# hex of statement fetching response
hexOfStatementFetchingResponse: "0x0001000000050505050505050505050505050505050505050505050505050505050505050548215b9d322601e5b1a95164cea0dc4626f545f98343d07f1551eb9543c4b147050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505c67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b8605050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505050505040c01020300010c0102030c0102030500000000000000"
Loading