diff --git a/dot/parachain/approval_distribution_message_test.go b/dot/parachain/approval_distribution_message_test.go index 5a05613915c..e4d9982d4a0 100644 --- a/dot/parachain/approval_distribution_message_test.go +++ b/dot/parachain/approval_distribution_message_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" ) -var hash = common.MustHexToHash("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") +var hashA = common.MustHexToHash("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") func TestEncodeApprovalDistributionMessageAssignmentModulo(t *testing.T) { approvalDistributionMessage := NewApprovalDistributionMessageVDT() @@ -37,7 +37,7 @@ func TestEncodeApprovalDistributionMessageAssignmentModulo(t *testing.T) { approvalDistributionMessage.Set(Assignments{ Assignment{ - IndirectAssignmentCert: fakeAssignmentCert(hash, parachaintypes.ValidatorIndex(1), false), + IndirectAssignmentCert: fakeAssignmentCert(hashA, parachaintypes.ValidatorIndex(1), false), CandidateIndex: 4, }, }) @@ -64,7 +64,7 @@ func TestEncodeApprovalDistributionMessageAssignmentDelay(t *testing.T) { approvalDistributionMessage.Set(Assignments{ Assignment{ - IndirectAssignmentCert: fakeAssignmentCert(hash, parachaintypes.ValidatorIndex(2), true), + IndirectAssignmentCert: fakeAssignmentCert(hashA, parachaintypes.ValidatorIndex(2), true), CandidateIndex: 2, }, }) @@ -113,7 +113,7 @@ func TestEncodeApprovalDistributionMessageApprovals(t *testing.T) { approvalDistributionMessage.Set(Approvals{ IndirectSignedApprovalVote{ - BlockHash: hash, + BlockHash: hashA, CandidateIndex: CandidateIndex(2), ValidatorIndex: parachaintypes.ValidatorIndex(3), Signature: ValidatorSignature{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -141,7 +141,7 @@ func TestDecodeApprovalDistributionMessageAssignmentModulo(t *testing.T) { expectedApprovalDistributionMessage := NewApprovalDistributionMessageVDT() expectedApprovalDistributionMessage.Set(Assignments{ Assignment{ - IndirectAssignmentCert: fakeAssignmentCert(hash, parachaintypes.ValidatorIndex(2), false), + IndirectAssignmentCert: fakeAssignmentCert(hashA, parachaintypes.ValidatorIndex(2), false), CandidateIndex: 4, }, }) @@ -161,7 +161,7 @@ func TestDecodeApprovalDistributionMessageApprovals(t *testing.T) { expectedApprovalDistributionMessage := NewApprovalDistributionMessageVDT() expectedApprovalDistributionMessage.Set(Approvals{ IndirectSignedApprovalVote{ - BlockHash: hash, + BlockHash: hashA, CandidateIndex: CandidateIndex(2), ValidatorIndex: parachaintypes.ValidatorIndex(3), Signature: ValidatorSignature{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, diff --git a/dot/parachain/service.go b/dot/parachain/service.go index 9fb2596209d..dfa5294d3a7 100644 --- a/dot/parachain/service.go +++ b/dot/parachain/service.go @@ -8,6 +8,7 @@ import ( "time" "github.com/ChainSafe/gossamer/dot/network" + "github.com/ChainSafe/gossamer/internal/log" "github.com/ChainSafe/gossamer/lib/common" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/protocol" @@ -22,6 +23,8 @@ type Service struct { Network Network } +var logger = log.NewFromGlobal(log.AddContext("pkg", "parachain")) + func NewService(net Network, forkID string, genesisHash common.Hash) (*Service, error) { validationProtocolID := GeneratePeersetProtocolName( ValidationProtocolName, forkID, genesisHash, ValidationProtocolVersion) @@ -120,7 +123,22 @@ func (s Service) run() { collationMessage := CollationProtocolV1{} s.Network.GossipMessage(&collationMessage) - validationMessage := ValidationProtocolV1{} + statementDistributionLargeStatement := StatementDistribution{NewStatementDistributionMessage()} + err := statementDistributionLargeStatement.Set(SecondedStatementWithLargePayload{ + RelayParent: common.Hash{}, + CandidateHash: CandidateHash{Value: common.Hash{}}, + SignedBy: 5, + Signature: ValidatorSignature{}, + }) + if err != nil { + logger.Errorf("creating test statement message: %w\n", err) + } + + validationMessage := NewValidationProtocolVDT() + err = validationMessage.Set(statementDistributionLargeStatement) + if err != nil { + logger.Errorf("creating test validation message: %w\n", err) + } s.Network.GossipMessage(&validationMessage) } diff --git a/dot/parachain/testdata/statement_distribution_message.yaml b/dot/parachain/testdata/statement_distribution_message.yaml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/dot/parachain/testdata/validation_protocol.yaml b/dot/parachain/testdata/validation_protocol.yaml new file mode 100644 index 00000000000..224e4181f7d --- /dev/null +++ b/dot/parachain/testdata/validation_protocol.yaml @@ -0,0 +1,13 @@ +validatorSignature: "0xc67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b86" + +collatorID : "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" + +approvalDistributionMessageAssignments: "0x040004aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0100000000020000000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f200102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4004000000" + +approvalDistributionMessageApprovals: "0x040104aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0a0000000b000000c67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b86" + +statementDistributionMessageLargeStatement: "0x0301aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa05000000c67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b86" + +statementDistributionMessageStatement: "0x0300aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0101000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaad43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b86aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa040c01020300010c0102030c010203050000000000000005000000c67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b86" + +bitfieldDistribution: "0x0100aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa80ffffffff00000000c67cb93bf0a36fcee3d29de8a6a69a759659680acf486475e0a2552a5fbed87e45adce5f290698d8596095722b33599227f7461f51af8617c8be74b894cf1b86" \ No newline at end of file diff --git a/dot/parachain/validation_protocol.go b/dot/parachain/validation_protocol.go index 8c390289c24..4dc800dd79a 100644 --- a/dot/parachain/validation_protocol.go +++ b/dot/parachain/validation_protocol.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/ChainSafe/gossamer/dot/network" + parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/pkg/scale" "github.com/libp2p/go-libp2p/core/peer" @@ -14,17 +15,135 @@ import ( const MaxValidationMessageSize uint64 = 100 * 1024 -type ValidationProtocolV1 struct { - // TODO: Implement this struct https://github.com/ChainSafe/gossamer/issues/3318 +// UncheckedSignedAvailabilityBitfield a signed bitfield with signature not yet checked +type UncheckedSignedAvailabilityBitfield struct { + // The payload is part of the signed data. The rest is the signing context, + // which is known both at signing and at validation. + Payload scale.BitVec `scale:"1"` + + // The index of the validator signing this statement. + ValidatorIndex parachaintypes.ValidatorIndex `scale:"2"` + + // The signature by the validator of the signed payload. + Signature ValidatorSignature `scale:"3"` +} + +// Bitfield avalibility bitfield for given relay-parent hash +type Bitfield struct { + Hash common.Hash `scale:"1"` + UncheckedSignedAvailabilityBitfield UncheckedSignedAvailabilityBitfield `scale:"2"` +} + +// Index returns the VaryingDataType Index +func (Bitfield) Index() uint { + return 0 +} + +// BitfieldDistributionMessage Network messages used by bitfield distribution subsystem +type BitfieldDistributionMessage scale.VaryingDataType + +// NewBitfieldDistributionMessageVDT returns a new BitfieldDistributionMessage VaryingDataType +func NewBitfieldDistributionMessageVDT() BitfieldDistributionMessage { + vdt := scale.MustNewVaryingDataType(Bitfield{}) + return BitfieldDistributionMessage(vdt) +} + +// New creates new BitfieldDistributionMessage +func (BitfieldDistributionMessage) New() BitfieldDistributionMessage { + return NewBitfieldDistributionMessageVDT() +} + +// Set will set a VaryingDataTypeValue using the underlying VaryingDataType +func (bdm *BitfieldDistributionMessage) Set(val scale.VaryingDataTypeValue) (err error) { + vdt := scale.VaryingDataType(*bdm) + err = vdt.Set(val) + if err != nil { + return fmt.Errorf("setting value to varying data type: %w", err) + } + + *bdm = BitfieldDistributionMessage(vdt) + return nil +} + +// Value returns the value from the underlying VaryingDataType +func (bdm *BitfieldDistributionMessage) Value() (scale.VaryingDataTypeValue, error) { + vdt := scale.VaryingDataType(*bdm) + return vdt.Value() +} + +// BitfieldDistribution struct holding BitfieldDistributionMessage +type BitfieldDistribution struct { + BitfieldDistributionMessage +} + +// Index VaryingDataType index of Bitfield Distribution +func (BitfieldDistribution) Index() uint { + return 1 +} + +// ApprovalDistribution struct holding ApprovalDistributionMessage +type ApprovalDistribution struct { + ApprovalDistributionMessage +} + +// Index VaryingDataType index of ApprovalDistribution +func (ApprovalDistribution) Index() uint { + return 4 +} + +// StatementDistribution struct holding StatementDistributionMessage +type StatementDistribution struct { + StatementDistributionMessage +} + +// Index VaryingDataType index for StatementDistribution +func (StatementDistribution) Index() uint { + return 3 +} + +// ValidationProtocol VaryingDataType for ValidationProtocol +type ValidationProtocol scale.VaryingDataType + +// NewValidationProtocolVDT constructor or ValidationProtocol VaryingDataType +func NewValidationProtocolVDT() ValidationProtocol { + vdt, err := scale.NewVaryingDataType(BitfieldDistribution{}, StatementDistribution{}, ApprovalDistribution{}) + if err != nil { + panic(err) + } + return ValidationProtocol(vdt) +} + +// New returns new ValidationProtocol VDT +func (ValidationProtocol) New() ValidationProtocol { + return NewValidationProtocolVDT() +} + +// Value returns the value from the underlying VaryingDataType +func (vp *ValidationProtocol) Value() (scale.VaryingDataTypeValue, error) { + vdt := scale.VaryingDataType(*vp) + return vdt.Value() +} + +// Set will set a VaryingDataTypeValue using the underlying VaryingDataType +func (vp *ValidationProtocol) Set(val scale.VaryingDataTypeValue) (err error) { + vdt := scale.VaryingDataType(*vp) + err = vdt.Set(val) + if err != nil { + return fmt.Errorf("setting value to varying data type: %w", err) + } + + *vp = ValidationProtocol(vdt) + return nil + } // Type returns ValidationMsgType -func (*ValidationProtocolV1) Type() network.MessageType { +func (*ValidationProtocol) Type() network.MessageType { return network.ValidationMsgType } // Hash returns the hash of the CollationProtocolV1 -func (vp *ValidationProtocolV1) Hash() (common.Hash, error) { +func (vp *ValidationProtocol) Hash() (common.Hash, error) { encMsg, err := vp.Encode() if err != nil { return common.Hash{}, fmt.Errorf("cannot encode message: %w", err) @@ -34,7 +153,7 @@ func (vp *ValidationProtocolV1) Hash() (common.Hash, error) { } // Encode a collator protocol message using scale encode -func (vp *ValidationProtocolV1) Encode() ([]byte, error) { +func (vp *ValidationProtocol) Encode() ([]byte, error) { enc, err := scale.Marshal(*vp) if err != nil { return enc, err @@ -43,7 +162,7 @@ func (vp *ValidationProtocolV1) Encode() ([]byte, error) { } func decodeValidationMessage(in []byte) (network.NotificationsMessage, error) { - validationMessage := ValidationProtocolV1{} + validationMessage := ValidationProtocol{} err := scale.Unmarshal(in, &validationMessage) if err != nil { diff --git a/dot/parachain/validation_protocol_test.go b/dot/parachain/validation_protocol_test.go index b61928825bf..0a958bfdb22 100644 --- a/dot/parachain/validation_protocol_test.go +++ b/dot/parachain/validation_protocol_test.go @@ -4,11 +4,314 @@ package parachain import ( + _ "embed" + "fmt" "testing" + parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" + "github.com/ChainSafe/gossamer/lib/common" + "github.com/ChainSafe/gossamer/pkg/scale" "github.com/stretchr/testify/require" + "gopkg.in/yaml.v3" ) +//go:embed testdata/validation_protocol.yaml + +var testValidationProtocolHexRaw string + +var testValidationProtocolHex map[string]string + +func init() { + err := yaml.Unmarshal([]byte(testValidationProtocolHexRaw), &testValidationProtocolHex) + if err != nil { + fmt.Printf("Error unmarshaling test data: %s\n", err) + return + } +} + +func TestMarshalUnMarshalValidationProtocol(t *testing.T) { + t.Parallel() + /* ValidationProtocol with ApprovalDistribution with Assignments Rust code + fn try_msg_assignments_encode() { + let hash = Hash::repeat_byte(0xAA); + let validator_index = ValidatorIndex(1); + let cert = fake_assignment_cert(hash, validator_index); + let assignments = vec![(cert.clone(), 4u32)]; + let msg = protocol_v1::ApprovalDistributionMessage::Assignments(assignments.clone()); + let val_proto = protocol_v1::ValidationProtocol::ApprovalDistribution(msg.clone()); + println!("encode validation proto => {:?}\n\n", val_proto.encode()); + } + */ + approvalDistribution := ApprovalDistribution{NewApprovalDistributionMessageVDT()} + approvalDistribution.Set(Assignments{ + Assignment{ + IndirectAssignmentCert: fakeAssignmentCert(hashA, parachaintypes.ValidatorIndex(1), false), + CandidateIndex: 4, + }, + }) + vpApprovalDistributionAssignments := NewValidationProtocolVDT() + vpApprovalDistributionAssignments.Set(approvalDistribution) + vpApprovalDistributionAssignmentsValue, err := vpApprovalDistributionAssignments.Value() + require.NoError(t, err) + + /* ValidationProtocol with ApprovalDistribution with Approvals rust code: + fn try_msg_approvals_encode() { + let hash = Hash::repeat_byte(0xAA); + let candidate_index = 0u32; + let validator_index = ValidatorIndex(0); + let approval = IndirectSignedApprovalVote { + block_hash: hash, + candidate_index, + validator: validator_index, + signature: dummy_signature(), + }; + let msg = protocol_v1::ApprovalDistributionMessage::Approvals(vec![approval.clone()]); + let val_proto = protocol_v1::ValidationProtocol::ApprovalDistribution(msg.clone()); + println!("encode validation proto => {:?}\n\n", val_proto.encode()); + } + */ + var validatorSignature ValidatorSignature + tempSignature := common.MustHexToBytes(testValidationProtocolHex["validatorSignature"]) + copy(validatorSignature[:], tempSignature) + + approvalDistributionApprovals := ApprovalDistribution{NewApprovalDistributionMessageVDT()} + approvalDistributionApprovals.Set(Approvals{ + IndirectSignedApprovalVote{ + BlockHash: hashA, + CandidateIndex: 10, + ValidatorIndex: 11, + Signature: validatorSignature, + }, + }) + + vpApprovalDistributionApprovals := NewValidationProtocolVDT() + vpApprovalDistributionApprovals.Set(approvalDistributionApprovals) + vpApprovalDistributionApprovalsValue, err := vpApprovalDistributionApprovals.Value() + require.NoError(t, err) + + /* ValidationProtocol with StatementDistribution with Statement rust code: + fn try_validation_protocol_statement_distribution_full_statement() { + let hash1 = Hash::repeat_byte(170); + let val_sign = ValidatorSignature::from( + Signature([198, 124, 185, 59, 240, 163, 111, 206, 227, 210, 157, 232, 166, 166, 154, 117, 150, 89, + 104, 10, 207, 72, 100, 117, 224, 162, 85, 42, 95, 190, 216, 126, 69, 173, 206, 95, 41, 6, 152, + 216, 89, 96, 149, 114, 43, 51, 89, 146, 39, 247, 70, 31, 81, 175, 134, 23, 200, 190, 116, 184, + 148, 207, 27, 134])); + let keystore: KeystorePtr = Arc::new(LocalKeystore::in_memory()); + let collator_result = Keystore::sr25519_generate_new( + &*keystore, + ValidatorId::ID, + Some(&Sr25519Keyring::Alice.to_seed()), + ); + let collator = collator_result.unwrap(); + let collsign = CollatorSignature::from(Signature([198, 124, 185, 59, 240, 163, 111, 206, 227, 210, 157, 232, + 166, 166, 154, 117, 150, 89, 104, 10, 207, 72, 100, 117, 224, 162, 85, 42, 95, 190, 216, 126, 69, 173, 206, + 95, 41, 6, 152, 216, 89, 96, 149, 114, 43, 51, 89, 146, 39, 247, 70, 31, 81, 175, 134, 23, 200, 190, 116, + 184, 148, 207, 27, 134])); + let candidate_descriptor = CandidateDescriptor{ + para_id: 1.into(), + relay_parent: hash1, + collator: polkadot_primitives::CollatorId::from(collator), + persisted_validation_data_hash: hash1, + pov_hash: hash1, + erasure_root: hash1, + signature: collsign, + para_head: hash1, + validation_code_hash: ValidationCodeHash::from(hash1) + }; + let commitments_new = CandidateCommitments{ + upward_messages: vec![vec![1, 2, 3]].try_into().expect("error - upward_messages"), + horizontal_messages: vec![].try_into().expect("error - horizontal_messages"), + head_data: HeadData(vec![1, 2, 3]), + hrmp_watermark: 0_u32, + new_validation_code: ValidationCode(vec![1, 2, 3]).try_into().expect("error - new_validation_code"), + processed_downward_messages: 5 + }; + let committed_candidate_receipt = CommittedCandidateReceipt { + descriptor: candidate_descriptor, commitments: commitments_new }; + let statement_second = Statement::Seconded(committed_candidate_receipt); + let unchecked_signed_full_statement_second = UncheckedSignedFullStatement::new( + statement_second, ValidatorIndex(5), val_sign.clone()); + let sdm_statement_second = protocol_v1::StatementDistributionMessage::Statement(hash1, + unchecked_signed_full_statement_second); + let validation_sdm_statement = protocol_v1::ValidationProtocol::StatementDistribution(sdm_statement_second); + println!("encode validation SecondedStatement => {:?}\n\n", validation_sdm_statement.encode()); + + } + */ + var collatorID parachaintypes.CollatorID + tempID := common.MustHexToBytes(testValidationProtocolHex["collatorID"]) + copy(collatorID[:], tempID) + var collatorSignature parachaintypes.CollatorSignature + copy(collatorSignature[:], tempSignature) + + statementSecond := Seconded{ + Descriptor: parachaintypes.CandidateDescriptor{ + ParaID: 1, + RelayParent: hashA, + Collator: collatorID, + PersistedValidationDataHash: hashA, + PovHash: hashA, + ErasureRoot: hashA, + Signature: collatorSignature, + ParaHead: hashA, + ValidationCodeHash: parachaintypes.ValidationCodeHash(hashA), + }, + Commitments: parachaintypes.CandidateCommitments{ + UpwardMessages: []parachaintypes.UpwardMessage{[]byte{1, 2, 3}}, + HorizontalMessages: nil, + NewValidationCode: ¶chaintypes.ValidationCode{1, 2, 3}, + HeadData: parachaintypes.HeadData{Data: []byte{1, 2, 3}}, + ProcessedDownwardMessages: 5, + HrmpWatermark: 0, + }, + } + statement := NewStatement() + statement.Set(statementSecond) + + statementDistributionStatement := StatementDistribution{NewStatementDistributionMessage()} + statementDistributionStatement.Set(SignedFullStatement{ + Hash: hashA, + UncheckedSignedFullStatement: UncheckedSignedFullStatement{ + Payload: statement, + ValidatorIndex: 5, + Signature: validatorSignature, + }, + }) + + vpStatementDistributionStatement := NewValidationProtocolVDT() + vpStatementDistributionStatement.Set(statementDistributionStatement) + vpStatementDistributionStatementValue, err := vpStatementDistributionStatement.Value() + require.NoError(t, err) + + /* ValidationProtocol with StatementDistribution with Large Statement rust code + fn try_validation_protocol_statement_distribution() { + let hash1 = Hash::repeat_byte(170); + let val_sign = ValidatorSignature::from( + Signature([198, 124, 185, 59, 240, 163, 111, 206, 227, 210, 157, 232, 166, 166, 154, 117, 150, 89, + 104, 10, 207, 72, 100, 117, 224, 162, 85, 42, 95, 190, 216, 126, 69, 173, 206, 95, 41, 6, 152, + 216, 89, 96, 149, 114, 43, 51, 89, 146, 39, 247, 70, 31, 81, 175, 134, 23, 200, 190, 116, 184, + 148, 207, 27, 134])); + let sdm_large_statement = protocol_v1::StatementDistributionMessage::LargeStatement(StatementMetadata{ + relay_parent: hash1, + candidate_hash: CandidateHash(hash1), + signed_by: ValidatorIndex(5_u32), + signature: val_sign.clone(), + }); + let validation_sdm_large_statement = protocol_v1::ValidationProtocol::StatementDistribution(sdm_large_statement); + println!("encode validation SecondedStatementWithLargePayload => {:?}\n\n", validation_sdm_large_statement.encode()); + } + */ + statementDistributionLargeStatement := StatementDistribution{NewStatementDistributionMessage()} + statementDistributionLargeStatement.Set(SecondedStatementWithLargePayload{ + RelayParent: hashA, + CandidateHash: CandidateHash{Value: hashA}, + SignedBy: 5, + Signature: validatorSignature, + }) + + vpStatementDistributionLargeStatement := NewValidationProtocolVDT() + vpStatementDistributionLargeStatement.Set(statementDistributionLargeStatement) + vpStatementDistributionLargeStatementValue, err := vpStatementDistributionLargeStatement.Value() + require.NoError(t, err) + + /* ValidationProtocol with BitfieldDistribution rust code + fn try_validation_protocol_bitfield_distribution_a() { + let hash_a :Hash = [170; 32].into(); + let keystore: KeystorePtr = Arc::new(MemoryKeystore::new()); + let payload = AvailabilityBitfield(bitvec![u8, bitvec::order::Lsb0; 1u8; 32]); + let signing_context = SigningContext { session_index: 1, parent_hash: hash_a.clone() }; + let validator_0 = + Keystore::sr25519_generate_new(&*keystore, ValidatorId::ID, None).expect("key created"); + let valid_signed = Signed::::sign( + &keystore, + payload, + &signing_context, + ValidatorIndex(0), + &validator_0.into(), + ) + .ok() + .flatten() + .expect("should be signed"); + let bitfield_distribition_message = protocol_v1::BitfieldDistributionMessage::Bitfield( + hash_a, + valid_signed.into(), + ); + let val_proto = ValidationProtocol::BitfieldDistribution(bitfield_distribition_message.clone()); + println!("encode validation proto => {:?}\n\n", val_proto.encode()); + } + */ + bitfieldDistribution := BitfieldDistribution{NewBitfieldDistributionMessageVDT()} + bitfieldDistribution.Set(Bitfield{ + Hash: hashA, + UncheckedSignedAvailabilityBitfield: UncheckedSignedAvailabilityBitfield{ + Payload: scale.NewBitVec([]bool{true, true, true, true, true, true, true, true, true, true, true, + true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, + true, true, true, true}), + ValidatorIndex: 0, + Signature: validatorSignature, + }, + }) + + vpBitfieldDistribution := NewValidationProtocolVDT() + vpBitfieldDistribution.Set(bitfieldDistribution) + vpBitfieldDistributionVal, err := vpBitfieldDistribution.Value() + require.NoError(t, err) + + testCases := map[string]struct { + enumValue scale.VaryingDataTypeValue + encodingValue []byte + }{ + "ValidationProtocol_with_ApprovalDistribution_with_Assignments": { + enumValue: vpApprovalDistributionAssignmentsValue, + encodingValue: common.MustHexToBytes(testValidationProtocolHex["approvalDistributionMessageAssignments"]), + }, + "ValidationProtocol_with_ApprovalDistribution_with_Approvals": { + enumValue: vpApprovalDistributionApprovalsValue, + encodingValue: common.MustHexToBytes(testValidationProtocolHex["approvalDistributionMessageApprovals"]), + }, + "ValidationProtocol_with_StatementDistribution_with_Statement": { + enumValue: vpStatementDistributionStatementValue, + encodingValue: common.MustHexToBytes(testValidationProtocolHex["statementDistributionMessageStatement"]), + }, + "ValidationProtocol_with_StatementDistribution_with_Large_Statement": { + enumValue: vpStatementDistributionLargeStatementValue, + encodingValue: common.MustHexToBytes(testValidationProtocolHex["statementDistributionMessageLargeStatement"]), + }, + "ValidationProtocol_with_BitfieldDistribution": { + enumValue: vpBitfieldDistributionVal, + encodingValue: common.MustHexToBytes(testValidationProtocolHex["bitfieldDistribution"]), + }, + } + + for name, c := range testCases { + c := c + t.Run("unmarshal "+name, func(t *testing.T) { + t.Parallel() + + validationProtocol := NewValidationProtocolVDT() + + err := scale.Unmarshal(c.encodingValue, &validationProtocol) + require.NoError(t, err) + + validationProtocolDecoded, err := validationProtocol.Value() + require.NoError(t, err) + require.Equal(t, c.enumValue, validationProtocolDecoded) + }) + t.Run("marshal "+name, func(t *testing.T) { + t.Parallel() + + validationProtocol := NewValidationProtocolVDT() + err := validationProtocol.Set(c.enumValue) + require.NoError(t, err) + + encoded, err := scale.Marshal(validationProtocol) + require.NoError(t, err) + require.Equal(t, c.encodingValue, encoded) + }) + } +} + func TestDecodeValidationHandshake(t *testing.T) { t.Parallel() diff --git a/lib/runtime/wasmer/testdata/parachain.yaml b/lib/runtime/wasmer/testdata/parachain.yaml index f3377464c1b..1698154e4f0 100644 --- a/lib/runtime/wasmer/testdata/parachain.yaml +++ b/lib/runtime/wasmer/testdata/parachain.yaml @@ -23,7 +23,7 @@ storage: # paras.currentCodeHash - key: "0xcd710b30bd2eab0352ddcc26417aa194e2d1c22ba0a888147714a3487bd51c63b6ff6f7d467b87a9e8030000" - value: "0xcafdc44448ed62f5f67e5c340b420c51fe3bee7c1577f9fa0e819383b5145337" + value: "0xcafdc44448ed62f5f67e5c340b420c51fe3bee7c1577f9fa0e819383b5145337" # paras.heads[paraID=1000]: - key: "0xcd710b30bd2eab0352ddcc26417aa1941b3c252fcb29d88eff4f3de5de4476c3b6ff6f7d467b87a9e8030000" value: "0xb9a9c9a758ed261aad10014bf0aeecd0d0275133e6b76703675898c7aa330a512ea01801c790de66e2f1c478bd632ff8bfe39354f43ce9ec0201601dfc3e730e3eb9826006a8441e6d7c2fe12a2612c3a064c9c5c6e1e2d32e50811f9619d6fd61f00b1f08066175726120f3635e080000000005617572610101147e68472ba82f29d61c6b67914bd6ec6ee2e7279c12ca24130282ca574ab03d7a4516ccd5a2ee5e7be0558aba3253942c1be30a8b534d43ecf941c46144e28d" diff --git a/lib/runtime/wazero/instance.go b/lib/runtime/wazero/instance.go index 8371d4e9692..1a2a75110c7 100644 --- a/lib/runtime/wazero/instance.go +++ b/lib/runtime/wazero/instance.go @@ -1046,7 +1046,7 @@ func (in *Instance) ParachainHostSessionInfo(sessionIndex parachaintypes.Session return sessionInfo, nil } -func (in *Instance) RandomSeed() { +func (*Instance) RandomSeed() { panic("unimplemented") } func (*Instance) OffchainWorker() {