diff --git a/dot/parachain/backing/candidate_backing_test.go b/dot/parachain/backing/candidate_backing_test.go index f2bbcb7ee7..224cbeabfc 100644 --- a/dot/parachain/backing/candidate_backing_test.go +++ b/dot/parachain/backing/candidate_backing_test.go @@ -11,6 +11,8 @@ import ( availabilitystore "github.com/ChainSafe/gossamer/dot/parachain/availability-store" candidatevalidation "github.com/ChainSafe/gossamer/dot/parachain/candidate-validation" collatorprotocolmessages "github.com/ChainSafe/gossamer/dot/parachain/collator-protocol/messages" + provisionermessages "github.com/ChainSafe/gossamer/dot/parachain/provisioner/messages" + parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/lib/crypto/sr25519" @@ -80,7 +82,7 @@ func mockOverseer(t *testing.T, subsystemToOverseer chan any) { case parachaintypes.ProspectiveParachainsMessageIntroduceCandidate: data.Ch <- nil case parachaintypes.ProspectiveParachainsMessageCandidateSeconded, - parachaintypes.ProvisionerMessageProvisionableData, + provisionermessages.ProvisionableData, parachaintypes.ProspectiveParachainsMessageCandidateBacked, collatorprotocolmessages.Backed, parachaintypes.StatementDistributionMessageBacked: diff --git a/dot/parachain/backing/integration_test.go b/dot/parachain/backing/integration_test.go index 41c2f0cfc5..1655a9fa14 100644 --- a/dot/parachain/backing/integration_test.go +++ b/dot/parachain/backing/integration_test.go @@ -13,6 +13,7 @@ import ( candidatevalidation "github.com/ChainSafe/gossamer/dot/parachain/candidate-validation" collatorprotocolmessages "github.com/ChainSafe/gossamer/dot/parachain/collator-protocol/messages" "github.com/ChainSafe/gossamer/dot/parachain/overseer" + provisionermessages "github.com/ChainSafe/gossamer/dot/parachain/provisioner/messages" parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" "github.com/ChainSafe/gossamer/lib/common" "github.com/ChainSafe/gossamer/lib/crypto" @@ -544,7 +545,7 @@ func TestCandidateReachesQuorum(t *testing.T) { } provisionerMessageProvisionableData := func(msg any) bool { - _, ok := msg.(parachaintypes.ProvisionerMessageProvisionableData) + _, ok := msg.(provisionermessages.ProvisionableData) return ok } diff --git a/dot/parachain/backing/per_relay_parent_state.go b/dot/parachain/backing/per_relay_parent_state.go index d9e90fb5a2..15d14d2838 100644 --- a/dot/parachain/backing/per_relay_parent_state.go +++ b/dot/parachain/backing/per_relay_parent_state.go @@ -11,6 +11,7 @@ import ( availabilitystore "github.com/ChainSafe/gossamer/dot/parachain/availability-store" candidatevalidation "github.com/ChainSafe/gossamer/dot/parachain/candidate-validation" collatorprotocolmessages "github.com/ChainSafe/gossamer/dot/parachain/collator-protocol/messages" + provisionermessages "github.com/ChainSafe/gossamer/dot/parachain/provisioner/messages" parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" "github.com/ChainSafe/gossamer/lib/runtime" wazero_runtime "github.com/ChainSafe/gossamer/lib/runtime/wazero" @@ -182,9 +183,9 @@ func (rpState *perRelayParentState) postImportStatement(subSystemToOverseer chan // // Backed candidates are bounded by the number of validators, // parachains, and the block production rate of the relay chain. - subSystemToOverseer <- parachaintypes.ProvisionerMessageProvisionableData{ - RelayParent: rpState.relayParent, - ProvisionableData: parachaintypes.ProvisionableDataBackedCandidate(backedCandidate.Candidate.ToPlain()), + subSystemToOverseer <- provisionermessages.ProvisionableData{ + RelayParent: rpState.relayParent, + Data: provisionermessages.ProvisionableDataBackedCandidate(backedCandidate.Candidate.ToPlain()), } } } @@ -203,9 +204,9 @@ func issueNewMisbehaviors(subSystemToOverseer chan<- any, relayParent common.Has // Misbehaviors are bounded by the number of validators and // the block production protocol. for _, misbehaviour := range misbehaviours { - subSystemToOverseer <- parachaintypes.ProvisionerMessageProvisionableData{ + subSystemToOverseer <- provisionermessages.ProvisionableData{ RelayParent: relayParent, - ProvisionableData: parachaintypes.ProvisionableDataMisbehaviorReport{ + Data: provisionermessages.ProvisionableDataMisbehaviorReport{ ValidatorIndex: validatorIndex, Misbehaviour: misbehaviour, }, diff --git a/dot/parachain/provisioner/messages/messages.go b/dot/parachain/provisioner/messages/messages.go new file mode 100644 index 0000000000..4a243a2a98 --- /dev/null +++ b/dot/parachain/provisioner/messages/messages.go @@ -0,0 +1,45 @@ +package provisionermessages + +import ( + parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" + "github.com/ChainSafe/gossamer/lib/common" +) + +var ( + _ Data = (*ProvisionableDataBackedCandidate)(nil) + _ Data = (*ProvisionableDataMisbehaviorReport)(nil) +) + +type RequestInherentData struct { + RelayParent common.Hash + ProvisionerInherentData chan ProvisionerInherentData +} + +type ProvisionerInherentData struct { +} + +// ProvisionerMessageProvisionableData is a provisioner message. +// This data should become part of a relay chain block. +type ProvisionableData struct { + RelayParent common.Hash + Data Data +} + +// Data becomes intrinsics or extrinsics which should be included in a future relay chain block. +type Data interface { + IsProvisionableData() +} + +// ProvisionableDataBackedCandidate is a provisionable data. +// The Candidate Backing subsystem believes that this candidate is valid, pending availability. +type ProvisionableDataBackedCandidate parachaintypes.CandidateReceipt + +func (ProvisionableDataBackedCandidate) IsProvisionableData() {} + +// ProvisionableDataMisbehaviorReport represents self-contained proofs of validator misbehaviour. +type ProvisionableDataMisbehaviorReport struct { + ValidatorIndex parachaintypes.ValidatorIndex + Misbehaviour parachaintypes.Misbehaviour +} + +func (ProvisionableDataMisbehaviorReport) IsProvisionableData() {} diff --git a/dot/parachain/provisioner/provisioner.go b/dot/parachain/provisioner/provisioner.go new file mode 100644 index 0000000000..79f0b7c5a9 --- /dev/null +++ b/dot/parachain/provisioner/provisioner.go @@ -0,0 +1,87 @@ +package provisioner + +import ( + "context" + "time" + + provisionermessages "github.com/ChainSafe/gossamer/dot/parachain/provisioner/messages" + parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" + "github.com/ChainSafe/gossamer/internal/log" + "github.com/ChainSafe/gossamer/lib/common" +) + +var logger = log.NewFromGlobal(log.AddContext("pkg", "provisioner")) + +// we expect an inherent to be ready after this time. +const INHERENT_TIMEOUT = time.Millisecond * 2000 + +type Provisioner struct { + // TODO This doesn't have to be a channel with buffer. + // The idea is to send a relay parent hash on this channel after INHERENT_TIMEOUT, open to design changes + inherentAfterDelay chan common.Hash +} + +func (p Provisioner) Run(ctx context.Context, overseerToSubSystem <-chan any) { + // TODO https://github.com/paritytech/polkadot-sdk/blob/e1460b5ee5f4490b428035aa4a72c1c99a262459/polkadot/node/core/provisioner/src/lib.rs#L177 + + for { + select { + // TODO: polkadot-rust changes reputation in batches, so we do the same? + case msg, ok := <-overseerToSubSystem: + if !ok { + return + } + err := p.processMessage(msg) + if err != nil { + logger.Errorf("processing overseer message: %w", err) + } + case <-p.inherentAfterDelay: + // This inherentAfterDelay gets populated while handling active leaves update signal + // TODO https://github.com/paritytech/polkadot-sdk/blob/e1460b5ee5f4490b428035aa4a72c1c99a262459/polkadot/node/core/provisioner/src/lib.rs#L181 + } + + } +} + +func (p Provisioner) processMessage(msg any) error { + switch msg.(type) { + case provisionermessages.RequestInherentData: + // TODO https://github.com/paritytech/polkadot-sdk/blob/e1460b5ee5f4490b428035aa4a72c1c99a262459/polkadot/node/core/provisioner/src/lib.rs#L253 + case provisionermessages.ProvisionableData: + // TODO https://github.com/paritytech/polkadot-sdk/blob/e1460b5ee5f4490b428035aa4a72c1c99a262459/polkadot/node/core/provisioner/src/lib.rs#L271 + default: + return parachaintypes.ErrUnknownOverseerMessage + } + + return nil + +} + +func (p Provisioner) Name() parachaintypes.SubSystemName { + return parachaintypes.Provisioner +} + +func (p Provisioner) ProcessActiveLeavesUpdateSignal(parachaintypes.ActiveLeavesUpdateSignal) error { + // TODO https://github.com/paritytech/polkadot-sdk/blob/e1460b5ee5f4490b428035aa4a72c1c99a262459/polkadot/node/core/provisioner/src/lib.rs#L173 + // https://github.com/paritytech/polkadot-sdk/blob/e1460b5ee5f4490b428035aa4a72c1c99a262459/polkadot/node/core/provisioner/src/lib.rs#L201 + return nil +} + +func (p Provisioner) ProcessBlockFinalizedSignal(parachaintypes.BlockFinalizedSignal) error { + // nothing to do here + return nil +} + +func (p Provisioner) Stop() {} + +type RequestInherentData struct { + RelayParent common.Hash + ProvisionerInherentData chan ProvisionerInherentData +} + +type ProvisionerInherentData struct { +} + +type ProvisionableData struct { + RelayParent common.Hash +} diff --git a/dot/parachain/types/overseer_message.go b/dot/parachain/types/overseer_message.go index e696ed0bb4..4e2cf3569c 100644 --- a/dot/parachain/types/overseer_message.go +++ b/dot/parachain/types/overseer_message.go @@ -6,8 +6,6 @@ package parachaintypes import "github.com/ChainSafe/gossamer/lib/common" var ( - _ ProvisionableData = (*ProvisionableDataBackedCandidate)(nil) - _ ProvisionableData = (*ProvisionableDataMisbehaviorReport)(nil) _ HypotheticalCandidate = (*HypotheticalCandidateIncomplete)(nil) _ HypotheticalCandidate = (*HypotheticalCandidateComplete)(nil) ) @@ -18,32 +16,6 @@ type OverseerFuncRes[T any] struct { Data T } -// ProvisionerMessageProvisionableData is a provisioner message. -// This data should become part of a relay chain block. -type ProvisionerMessageProvisionableData struct { - RelayParent common.Hash - ProvisionableData ProvisionableData -} - -// ProvisionableData becomes intrinsics or extrinsics which should be included in a future relay chain block. -type ProvisionableData interface { - IsProvisionableData() -} - -// ProvisionableDataBackedCandidate is a provisionable data. -// The Candidate Backing subsystem believes that this candidate is valid, pending availability. -type ProvisionableDataBackedCandidate CandidateReceipt - -func (ProvisionableDataBackedCandidate) IsProvisionableData() {} - -// ProvisionableDataMisbehaviorReport represents self-contained proofs of validator misbehaviour. -type ProvisionableDataMisbehaviorReport struct { - ValidatorIndex ValidatorIndex - Misbehaviour Misbehaviour -} - -func (ProvisionableDataMisbehaviorReport) IsProvisionableData() {} - // StatementDistributionMessageBacked is a statement distribution message. // it represents a message indicating that a candidate has received sufficient // validity votes from the backing group. If backed as a result of a local statement, diff --git a/dot/parachain/types/subsystems.go b/dot/parachain/types/subsystems.go index 0fed974f12..2492af1a06 100644 --- a/dot/parachain/types/subsystems.go +++ b/dot/parachain/types/subsystems.go @@ -18,6 +18,7 @@ const ( NetworkBridgeReceiver SubSystemName = "NetworkBridgeReceiver" ChainAPI SubSystemName = "ChainAPI" CandidateValidation SubSystemName = "CandidateValidation" + Provisioner SubSystemName = "Provisioner" ) var SubsystemRequestTimeout = 1 * time.Second