Skip to content

Commit

Permalink
Fix(lib/parachain): use actual forkID in parachain network protocol (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
axaysagathiya authored Aug 1, 2023
1 parent 3082b79 commit f94aa1e
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 23 deletions.
2 changes: 2 additions & 0 deletions dot/build_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (b *BuildSpec) ToJSON() ([]byte, error) {
ID: b.genesis.ID,
ChainType: b.genesis.ChainType,
Bootnodes: b.genesis.Bootnodes,
ForkID: b.genesis.ForkID,
ProtocolID: b.genesis.ProtocolID,
Properties: b.genesis.Properties,
Genesis: genesis.Fields{
Expand All @@ -45,6 +46,7 @@ func (b *BuildSpec) ToJSONRaw() ([]byte, error) {
ID: b.genesis.ID,
ChainType: b.genesis.ChainType,
Bootnodes: b.genesis.Bootnodes,
ForkID: b.genesis.ForkID,
ProtocolID: b.genesis.ProtocolID,
Properties: b.genesis.Properties,
Genesis: genesis.Fields{
Expand Down
5 changes: 5 additions & 0 deletions dot/build_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestBuildSpec_ToJSON(t *testing.T) {
"chainType": "",
"bootNodes": null,
"telemetryEndpoints": null,
"forkId": "",
"protocolId": "",
"genesis": {},
"properties": null,
Expand All @@ -51,6 +52,7 @@ func TestBuildSpec_ToJSON(t *testing.T) {
Name: "test",
ID: "ID",
ChainType: "chainType",
ForkID: "forkId",
ProtocolID: "protocol",
ConsensusEngine: "babe",
},
Expand All @@ -62,6 +64,7 @@ func TestBuildSpec_ToJSON(t *testing.T) {
"chainType": "chainType",
"bootNodes": null,
"telemetryEndpoints": null,
"forkId": "forkId",
"protocolId": "protocol",
"genesis": {},
"properties": null,
Expand Down Expand Up @@ -99,6 +102,7 @@ func TestBuildSpec_ToJSON(t *testing.T) {
"node2"
],
"telemetryEndpoints": null,
"forkId": "",
"protocolId": "protocol",
"genesis": {},
"properties": {
Expand Down Expand Up @@ -247,6 +251,7 @@ func TestBuildSpec_ToJSONRaw(t *testing.T) {
"chainType": "",
"bootNodes": null,
"telemetryEndpoints": null,
"forkId": "",
"protocolId": "",
"genesis": {},
"properties": null,
Expand Down
8 changes: 4 additions & 4 deletions dot/mock_node_builder_test.go

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

4 changes: 2 additions & 2 deletions dot/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type nodeBuilderIface interface {
dh *digest.Handler) (*core.Service, error)
createGRANDPAService(config *cfg.Config, st *state.Service, ks KeyStore,
net *network.Service, telemetryMailer Telemetry) (*grandpa.Service, error)
createParachainHostService(net *network.Service, genesishHash common.Hash) (*parachain.Service, error)
createParachainHostService(net *network.Service, forkID string, genesishHash common.Hash) (*parachain.Service, error)
newSyncService(config *cfg.Config, st *state.Service, finalityGadget BlockJustificationVerifier,
verifier *babe.VerificationManager, cs *core.Service, net *network.Service,
telemetryMailer Telemetry) (*dotsync.Service, error)
Expand Down Expand Up @@ -365,7 +365,7 @@ func newNode(config *cfg.Config,
}
nodeSrvcs = append(nodeSrvcs, fg)

phs, err := builder.createParachainHostService(networkSrvc, stateSrvc.Block.GenesisHash())
phs, err := builder.createParachainHostService(networkSrvc, gd.ForkID, stateSrvc.Block.GenesisHash())
if err != nil {
return nil, err
}
Expand Down
9 changes: 6 additions & 3 deletions dot/node_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestNewNode(t *testing.T) {
return stateSrvc, nil
})

phs, err := parachain.NewService(testNetworkService, common.Hash{})
phs, err := parachain.NewService(testNetworkService, "random_fork_id", common.Hash{})
require.NoError(t, err)

m.EXPECT().createRuntimeStorage(gomock.AssignableToTypeOf(&state.Service{})).Return(&runtime.
Expand Down Expand Up @@ -154,8 +154,11 @@ func TestNewNode(t *testing.T) {
})
m.EXPECT().createNetworkService(initConfig, gomock.AssignableToTypeOf(&state.Service{}),
gomock.AssignableToTypeOf(&telemetry.Mailer{})).Return(testNetworkService, nil)
m.EXPECT().createParachainHostService(gomock.AssignableToTypeOf(&network.Service{}),
gomock.AssignableToTypeOf(common.Hash{})).Return(phs, nil)
m.EXPECT().createParachainHostService(
gomock.AssignableToTypeOf(&network.Service{}),
gomock.AssignableToTypeOf("random_fork_id"),
gomock.AssignableToTypeOf(common.Hash{}),
).Return(phs, nil)

got, err := newNode(initConfig, ks, m, mockServiceRegistry)
assert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions dot/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,9 @@ func (nodeBuilder) createGRANDPAService(config *cfg.Config, st *state.Service, k
return grandpa.NewService(gsCfg)
}

func (nodeBuilder) createParachainHostService(net *network.Service, genesisHash common.Hash) (
func (nodeBuilder) createParachainHostService(net *network.Service, forkID string, genesisHash common.Hash) (
*parachain.Service, error) {
return parachain.NewService(net, genesisHash)
return parachain.NewService(net, forkID, genesisHash)
}

func (nodeBuilder) createBlockVerifier(st *state.Service) *babe.VerificationManager {
Expand Down
2 changes: 1 addition & 1 deletion dot/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestCreateJSONRawFile(t *testing.T) {
bs: &BuildSpec{genesis: NewTestGenesis(t)},
fp: filepath.Join(t.TempDir(), "/test.json"),
},
expectedHash: "f7f1b82c0ba16b20e36bfb462d7899af2c76728918f639f5c5ef0e91ff3e7077",
expectedHash: "ddedbc626806eb0f2a2eec5ade59a7141fedbff55e27021e3265a5f9000dec2e",
},
}
for _, tt := range tests {
Expand Down
23 changes: 16 additions & 7 deletions lib/babe/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,9 @@ func Test_verifyBlockEquivocation(t *testing.T) {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().GenesisHash().Return(common.Hash([32]byte{}))

expectedAuthorityId := types.AuthorityID(kp.Public().Encode())
var expectedAuthorityId types.AuthorityID
copy(expectedAuthorityId[:], kp.Public().Encode())

mockSlotState := NewMockSlotState(ctrl)
mockSlotState.
EXPECT().
Expand Down Expand Up @@ -790,7 +792,9 @@ func Test_verifyBlockEquivocation(t *testing.T) {
mockBlockState := NewMockBlockState(ctrl)
mockBlockState.EXPECT().GenesisHash().Return(common.Hash([32]byte{}))

expectedAuthorityId := types.AuthorityID(kp.Public().Encode())
var expectedAuthorityId types.AuthorityID
copy(expectedAuthorityId[:], kp.Public().Encode())

mockSlotState := NewMockSlotState(ctrl)
mockSlotState.
EXPECT().
Expand Down Expand Up @@ -821,7 +825,8 @@ func Test_verifyBlockEquivocation(t *testing.T) {
secondHeader.Number = 1
secondHeader.Hash()

expectedAuthorityId := types.AuthorityID(kp.Public().Encode())
var expectedAuthorityId types.AuthorityID
copy(expectedAuthorityId[:], kp.Public().Encode())

mockedEquivocationProof := &types.BabeEquivocationProof{
Offender: expectedAuthorityId,
Expand Down Expand Up @@ -878,7 +883,8 @@ func Test_verifyBlockEquivocation(t *testing.T) {
secondHeader.Number = 1
secondHeader.Hash()

expectedAuthorityId := types.AuthorityID(kp.Public().Encode())
var expectedAuthorityId types.AuthorityID
copy(expectedAuthorityId[:], kp.Public().Encode())

mockedEquivocationProof := &types.BabeEquivocationProof{
Offender: expectedAuthorityId,
Expand Down Expand Up @@ -1047,7 +1053,8 @@ func Test_verifier_verifyAuthorshipRightEquivocatory(t *testing.T) {
},
setupVerifier: func(t *testing.T, header *types.Header) *verifier {
const slot = uint64(1)
offenderPublicKey := types.AuthorityID(kp.Public().Encode())
var offenderPublicKey types.AuthorityID
copy(offenderPublicKey[:], kp.Public().Encode())

equivocationProof := &types.BabeEquivocationProof{
Offender: offenderPublicKey,
Expand Down Expand Up @@ -1108,7 +1115,8 @@ func Test_verifier_verifyAuthorshipRightEquivocatory(t *testing.T) {
},
setupVerifier: func(t *testing.T, header *types.Header) *verifier {
const slot = uint64(1)
offenderPublicKey := types.AuthorityID(kp.Public().Encode())
var offenderPublicKey types.AuthorityID
copy(offenderPublicKey[:], kp.Public().Encode())

equivocationProof := &types.BabeEquivocationProof{
Offender: offenderPublicKey,
Expand Down Expand Up @@ -1178,7 +1186,8 @@ func Test_verifier_verifyAuthorshipRightEquivocatory(t *testing.T) {
},
setupVerifier: func(t *testing.T, header *types.Header) *verifier {
const slot = uint64(1)
offenderPublicKey := types.AuthorityID(kp.Public().Encode())
var offenderPublicKey types.AuthorityID
copy(offenderPublicKey[:], kp.Public().Encode())

equivocationProof := &types.BabeEquivocationProof{
Offender: offenderPublicKey,
Expand Down
3 changes: 3 additions & 0 deletions lib/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Genesis struct {
ChainType string `json:"chainType"`
Bootnodes []string `json:"bootNodes"`
TelemetryEndpoints []interface{} `json:"telemetryEndpoints"`
ForkID string `json:"forkId"`
ProtocolID string `json:"protocolId"`
Genesis Fields `json:"genesis"`
Properties map[string]interface{} `json:"properties"`
Expand All @@ -33,6 +34,7 @@ type Data struct {
ChainType string
Bootnodes [][]byte
TelemetryEndpoints []*TelemetryEndpoint
ForkID string
ProtocolID string
Properties map[string]interface{}
ForkBlocks []string
Expand Down Expand Up @@ -210,6 +212,7 @@ func (g *Genesis) GenesisData() *Data {
ChainType: g.ChainType,
Bootnodes: common.StringArrayToBytes(g.Bootnodes),
TelemetryEndpoints: interfaceToTelemetryEndpoint(g.TelemetryEndpoints),
ForkID: g.ForkID,
ProtocolID: g.ProtocolID,
Properties: g.Properties,
ForkBlocks: g.ForkBlocks,
Expand Down
5 changes: 1 addition & 4 deletions lib/parachain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ type Service struct {
Network Network
}

func NewService(net Network, genesisHash common.Hash) (*Service, error) {
// TODO: Use actual fork id from chain spec #3373
forkID := ""

func NewService(net Network, forkID string, genesisHash common.Hash) (*Service, error) {
validationProtocolID := GeneratePeersetProtocolName(
ValidationProtocolName, forkID, genesisHash, ValidationProtocolVersion)

Expand Down

0 comments on commit f94aa1e

Please sign in to comment.