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(lib/runtime/wasmer): report grandpa equivocations #3007

Merged
merged 62 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
8a921b0
init structure for rt calls
jimjbrettj Nov 30, 2022
67c1222
create reportEquivocation method
jimjbrettj Nov 30, 2022
96c6115
wip
jimjbrettj Nov 30, 2022
6bef330
wip/implement generateKeyOwnershipProof
jimjbrettj Nov 30, 2022
d495c07
wip
jimjbrettj Dec 7, 2022
dcfc00f
wip
jimjbrettj Dec 7, 2022
383e1f5
wip
jimjbrettj Dec 8, 2022
e0ed43a
wip/testReportEquivocation
jimjbrettj Dec 12, 2022
f196c41
get submit equivocation report test working
jimjbrettj Dec 12, 2022
33c3f24
make blockNum uint64, proper encoding for equivProof, TODO/fix errors…
jimjbrettj Dec 15, 2022
f9190c3
wip/fix wasmer tests
jimjbrettj Dec 16, 2022
d2d4482
small changes post rebase
jimjbrettj Jan 4, 2023
71d842a
fix build
jimjbrettj Jan 4, 2023
90996c7
fix rpc/modules test
jimjbrettj Jan 4, 2023
d1b6e21
fix core tests
jimjbrettj Jan 4, 2023
88c3e33
fix grandpa test
jimjbrettj Jan 4, 2023
f094fa3
regenerated mocks
jimjbrettj Jan 4, 2023
98f4140
change vote block nuber to uint32
jimjbrettj Jan 5, 2023
6e8c1f4
fix submitEquicocationProof test
jimjbrettj Jan 6, 2023
a00c1e0
clean up PR TODO/fix lint
jimjbrettj Jan 6, 2023
6376710
fix sync tests
jimjbrettj Jan 9, 2023
2fd8605
fix rpc modules mocks
jimjbrettj Jan 9, 2023
09efb56
fix mocks and linting
jimjbrettj Jan 9, 2023
5abc2f8
remove deepsource issues
jimjbrettj Jan 9, 2023
940ca05
unit test for reportEquivocation
jimjbrettj Jan 9, 2023
3244d00
add copyright to new file
jimjbrettj Jan 9, 2023
5cde759
fix unmarshalling of key ownership proof
jimjbrettj Jan 9, 2023
145ae9b
make tests parallel
jimjbrettj Jan 9, 2023
ba47e41
user versioner interface, WIP/feedback
jimjbrettj Jan 10, 2023
cb55fbb
respond to feedback
jimjbrettj Jan 10, 2023
3fdea2c
tims feedback and resolve comments from yesterdays feedback
jimjbrettj Jan 11, 2023
0afb574
Update lib/grandpa/vote_message_integration_test.go
jimjbrettj Jan 11, 2023
e5d1137
Update lib/grandpa/vote_message_integration_test.go
jimjbrettj Jan 11, 2023
3ae01ee
Update lib/grandpa/vote_message_integration_test.go
jimjbrettj Jan 11, 2023
fc1413f
wip/feedback
jimjbrettj Jan 11, 2023
201cf30
respond to feedback
jimjbrettj Jan 11, 2023
02ae7ad
fix grandpa integration test
jimjbrettj Jan 11, 2023
a143b85
Update dot/types/grandpa_test.go
jimjbrettj Jan 12, 2023
2376207
Update dot/types/grandpa_test.go
jimjbrettj Jan 12, 2023
e3ce638
Update dot/types/grandpa_test.go
jimjbrettj Jan 12, 2023
0c9c355
Update lib/grandpa/interfaces.go
jimjbrettj Jan 12, 2023
b3ff0b6
Update lib/grandpa/vote_message.go
jimjbrettj Jan 12, 2023
bf0f3ce
Update lib/runtime/wasmer/exports.go
jimjbrettj Jan 12, 2023
46323ed
Update lib/runtime/wasmer/exports.go
jimjbrettj Jan 12, 2023
98b4997
Update lib/runtime/wasmer/exports.go
jimjbrettj Jan 12, 2023
ee97c9a
Update lib/runtime/wasmer/exports_test.go
jimjbrettj Jan 12, 2023
662ea7e
changes
jimjbrettj Jan 12, 2023
deb08da
wip/feedback
jimjbrettj Jan 12, 2023
6f94bd9
feedback
jimjbrettj Jan 12, 2023
a7d3c76
lint
jimjbrettj Jan 12, 2023
971cc44
rename opaqueKeyOwnershipProof to GrandpaOpaqueKeyOwnershipProof
jimjbrettj Jan 23, 2023
680ff90
fix mocks
jimjbrettj Jan 23, 2023
017cce8
wip/feedback
jimjbrettj Jan 26, 2023
1df1dd7
add sources to expected encodings
jimjbrettj Jan 26, 2023
4ffb931
feedback
jimjbrettj Jan 26, 2023
eeea55d
rebase
jimjbrettj Jan 26, 2023
915ac28
clean up mocks
jimjbrettj Jan 26, 2023
7a57342
rename checkForEquivocation to checkAndReportEquivocation
jimjbrettj Jan 27, 2023
8df6d0f
use snake case for tests
jimjbrettj Jan 30, 2023
578f0a5
rename equivocation vdt types
jimjbrettj Feb 1, 2023
419f569
respond to feedback
jimjbrettj Feb 2, 2023
16de290
move test helper out of common to test_helpers
jimjbrettj Feb 8, 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
6 changes: 6 additions & 0 deletions dot/core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto"
"github.com/ChainSafe/gossamer/lib/crypto/ed25519"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/runtime"
rtstorage "github.com/ChainSafe/gossamer/lib/runtime/storage"
Expand Down Expand Up @@ -54,6 +55,11 @@ type RuntimeInstance interface {
RandomSeed()
OffchainWorker()
GenerateSessionKeys()
GrandpaGenerateKeyOwnershipProof(authSetID uint64, authorityID ed25519.PublicKeyBytes) (
types.GrandpaOpaqueKeyOwnershipProof, error)
GrandpaSubmitReportEquivocationUnsignedExtrinsic(
equivocationProof types.GrandpaEquivocationProof, keyOwnershipProof types.GrandpaOpaqueKeyOwnershipProof,
) error
}

// BlockState interface for block state methods
Expand Down
30 changes: 30 additions & 0 deletions dot/core/mocks_test.go

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

6 changes: 6 additions & 0 deletions dot/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto/ed25519"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/services"
Expand Down Expand Up @@ -69,4 +70,9 @@ type runtimeInterface interface {
RandomSeed()
OffchainWorker()
GenerateSessionKeys()
GrandpaGenerateKeyOwnershipProof(authSetID uint64, authorityID ed25519.PublicKeyBytes) (
types.GrandpaOpaqueKeyOwnershipProof, error)
GrandpaSubmitReportEquivocationUnsignedExtrinsic(
equivocationProof types.GrandpaEquivocationProof, keyOwnershipProof types.GrandpaOpaqueKeyOwnershipProof,
) error
}
6 changes: 6 additions & 0 deletions dot/rpc/modules/interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package modules
import (
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto/ed25519"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/transaction"
Expand Down Expand Up @@ -39,4 +40,9 @@ type Runtime interface {
RandomSeed()
OffchainWorker()
GenerateSessionKeys()
GrandpaGenerateKeyOwnershipProof(authSetID uint64, authorityID ed25519.PublicKeyBytes) (
types.GrandpaOpaqueKeyOwnershipProof, error)
GrandpaSubmitReportEquivocationUnsignedExtrinsic(
equivocationProof types.GrandpaEquivocationProof, keyOwnershipProof types.GrandpaOpaqueKeyOwnershipProof,
) error
}
6 changes: 6 additions & 0 deletions dot/state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ChainSafe/chaindb"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto/ed25519"
"github.com/ChainSafe/gossamer/lib/keystore"
"github.com/ChainSafe/gossamer/lib/runtime"
"github.com/ChainSafe/gossamer/lib/transaction"
Expand Down Expand Up @@ -94,6 +95,11 @@ type Runtime interface {
RandomSeed()
OffchainWorker()
GenerateSessionKeys()
GrandpaGenerateKeyOwnershipProof(authSetID uint64, authorityID ed25519.PublicKeyBytes) (
types.GrandpaOpaqueKeyOwnershipProof, error)
GrandpaSubmitReportEquivocationUnsignedExtrinsic(
equivocationProof types.GrandpaEquivocationProof, keyOwnershipProof types.GrandpaOpaqueKeyOwnershipProof,
) error
}

// BabeConfigurer returns the babe configuration of the runtime.
Expand Down
30 changes: 30 additions & 0 deletions dot/sync/mock_runtime_test.go

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

63 changes: 63 additions & 0 deletions dot/types/grandpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,66 @@ type GrandpaVote struct {
func (v GrandpaVote) String() string {
return fmt.Sprintf("hash=%s number=%d", v.Hash, v.Number)
}

// GrandpaEquivocation is used to create a proof of equivocation
// https://github.com/paritytech/finality-grandpa/blob/19d251d0b0105d51a79d3c4532a9aae75a5035bd/src/lib.rs#L213 //nolint:lll
type GrandpaEquivocation struct {
jimjbrettj marked this conversation as resolved.
Show resolved Hide resolved
RoundNumber uint64
ID [32]byte
FirstVote GrandpaVote
FirstSignature [64]byte
SecondVote GrandpaVote
SecondSignature [64]byte
}
jimjbrettj marked this conversation as resolved.
Show resolved Hide resolved

// GrandpaEquivocationEnum is a wrapper object for GRANDPA equivocation proofs, useful for unifying prevote
// and precommit equivocations under a common type.
// https://github.com/paritytech/substrate/blob/fb22096d2ec6bf38e67ce811ad2c31415237a9a5/primitives/finality-grandpa/src/lib.rs#L272 //nolint:lll
type GrandpaEquivocationEnum scale.VaryingDataType
timwu20 marked this conversation as resolved.
Show resolved Hide resolved

// Set sets a VaryingDataTypeValue using the underlying VaryingDataType
func (ge *GrandpaEquivocationEnum) Set(value scale.VaryingDataTypeValue) (err error) {
vdt := scale.VaryingDataType(*ge)
err = vdt.Set(value)
if err != nil {
return err
}
*ge = GrandpaEquivocationEnum(vdt)
return nil
}

// Value will return the value from the underlying VaryingDataType
func (ge *GrandpaEquivocationEnum) Value() (value scale.VaryingDataTypeValue, err error) {
vdt := scale.VaryingDataType(*ge)
return vdt.Value()
}

// NewGrandpaEquivocation returns a new VaryingDataType to represent a grandpa Equivocation
func NewGrandpaEquivocation() *GrandpaEquivocationEnum {
vdt := scale.MustNewVaryingDataType(PreVote{}, PreCommit{})
ge := GrandpaEquivocationEnum(vdt)
return &ge
}

// PreVote equivocation type for a prevote
type PreVote GrandpaEquivocation

// Index returns VDT index
func (PreVote) Index() uint { return 0 }

// PreCommit equivocation type for a precommit
type PreCommit GrandpaEquivocation

// Index returns VDT index
func (PreCommit) Index() uint { return 1 }

// GrandpaOpaqueKeyOwnershipProof contains a key ownership proof for reporting equivocations
// https://github.com/paritytech/substrate/blob/fb22096d2ec6bf38e67ce811ad2c31415237a9a5/primitives/finality-grandpa/src/lib.rs#L533 //nolint:lll
type GrandpaOpaqueKeyOwnershipProof []byte

// GrandpaEquivocationProof is used to report grandpa equivocations
// https://github.com/paritytech/substrate/blob/fb22096d2ec6bf38e67ce811ad2c31415237a9a5/primitives/finality-grandpa/src/lib.rs#L238 //nolint:lll
type GrandpaEquivocationProof struct {
timwu20 marked this conversation as resolved.
Show resolved Hide resolved
SetID uint64
Equivocation GrandpaEquivocationEnum
}
Loading