Skip to content

Commit c6e1d82

Browse files
authored
Add ancestry to conformance (#506)
* Add ancestry to conformance
1 parent 386f182 commit c6e1d82

File tree

6 files changed

+246
-262
lines changed

6 files changed

+246
-262
lines changed

.github/workflows/go-ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,7 @@ jobs:
8888

8989
- name: execute traces-tiny tests
9090
run: make traces-tiny
91+
92+
- name: execute conformance tests
93+
run: make test-conformance
94+

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ build-conformance: build-bandersnatch build-erasurecoding
8888
mkdir -p pkg/conformance/bin
8989
go build -tags="tiny" -o pkg/conformance/bin/strawberry ./pkg/conformance/cmd/main.go
9090

91+
.PHONY: test-conformance
92+
## test-conformance: Runs conformance tests
93+
test-conformance: build-bandersnatch build-erasurecoding
94+
go test ./pkg/conformance/... -v $(DARWIN_TEST_GOFLAGS) --tags=tiny,conformance
95+
9196
.PHONY: run-target
9297
## run-target: Runs the conformance target with socket /tmp/jam_target.sock
9398
run-target:

internal/guaranteeing/guarantee.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// ∀x ∈ x : ∃h ∈ A : hT = xt ∧ H(h) = xl (eq. 11.35 v 0.7.0)
3030
// TODO: Make this configurable. Currently the test vectors and traces `do not use ancestry.
3131
// The conformance tests have the option to have it enabled or disabled.
32-
const Ancestry = false
32+
var Ancestry = false
3333

3434
// ValidateGuaranteExtrinsicAndReturnReporters validates the guarantees extrinsic according to section 11.4.
3535
// It performs all validity checks required for work report guarantees and returns the set of reporters.

pkg/conformance/cmd/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ func main() {
3333
trieStore := store.NewTrie(chain)
3434

3535
appName := []byte("strawberry")
36-
appVersion := conformance.Version{Major: 0, Minor: 0, Patch: 1}
37-
jamVersion := conformance.Version{Major: 0, Minor: 7, Patch: 1}
38-
features := conformance.FeatureFork
36+
appVersion := conformance.Version{Major: 0, Minor: 0, Patch: 2}
37+
jamVersion := conformance.Version{Major: 0, Minor: 7, Patch: 2}
38+
features := conformance.FeatureAncestryAndFork
3939
node := conformance.NewNode(*socketPath, chain, trieStore, appName, appVersion, jamVersion, features)
4040
if err := node.Start(); err != nil {
4141
log.Fatalf("Failed to start Node: %v", err)

pkg/conformance/node.go

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
"log"
99
"net"
1010
"os"
11-
"strings"
1211
"sync"
1312

1413
"github.com/eigerco/strawberry/pkg/network/handlers"
1514
"github.com/eigerco/strawberry/pkg/serialization/codec/jam"
1615

1716
"github.com/eigerco/strawberry/internal/crypto"
17+
"github.com/eigerco/strawberry/internal/guaranteeing"
1818
"github.com/eigerco/strawberry/internal/state"
1919
"github.com/eigerco/strawberry/internal/state/merkle"
2020
"github.com/eigerco/strawberry/internal/state/serialization"
@@ -49,6 +49,10 @@ type Node struct {
4949

5050
// NewNode create a new conformance testing node
5151
func NewNode(socketPath string, chain *store.Chain, trie *store.Trie, appName []byte, appVersion, jamVersion Version, features Features) *Node {
52+
// Enable ancestry validation if the feature flag is set
53+
if features == FeatureAncestry || features == FeatureAncestryAndFork {
54+
guaranteeing.Ancestry = true
55+
}
5256
peerInfo := PeerInfo{
5357
FuzzVersion: 1,
5458
FuzzFeatures: features,
@@ -123,32 +127,7 @@ func (n *Node) handleConnection(conn net.Conn) {
123127

124128
responseMsg, err := n.messageHandler(msg)
125129
if err != nil {
126-
if strings.Contains(err.Error(), "preimage unneeded") {
127-
responseMsg = NewMessage(Error{Message: []byte("Chain error: block execution failure: preimages error: preimage not required")})
128-
} else if strings.Contains(err.Error(), "bad core index") {
129-
responseMsg = NewMessage(Error{Message: []byte("Chain error: block execution failure: reports error: bad core index for work report")})
130-
} else if strings.Contains(err.Error(), "wrong assignment") {
131-
responseMsg = NewMessage(Error{Message: []byte("Chain error: block execution failure: reports error: wrong core assignment")})
132-
} else if strings.Contains(err.Error(), "bad validator index") {
133-
responseMsg = NewMessage(Error{Message: []byte("Chain error: block execution failure: assurances error: bad attestation validator index")})
134-
} else if strings.Contains(err.Error(), "block seal or vrf signature is invalid") {
135-
responseMsg = NewMessage(Error{Message: []byte("Chain error: block header verification failure: BadSealSignature")})
136-
} else if strings.Contains(err.Error(), "unexpected author") {
137-
responseMsg = NewMessage(Error{Message: []byte("Chain error: block header verification failure: UnexpectedAuthor")})
138-
// responseMsg = NewMessage(Error{Message: []byte("Chain error: block verification failure: unexpected author")}) //fauty vectors have the error in different format
139-
} else if strings.Contains(err.Error(), "epoch marker") {
140-
responseMsg = NewMessage(Error{Message: []byte("Chain error: block header verification failure: InvalidEpochMark")})
141-
// responseMsg = NewMessage(Error{Message: []byte("Chain error: block header verification failure: InvalidEpochMark")}) //fauty vectors have the error in different format
142-
} else if strings.Contains(err.Error(), "winning ticket marker") {
143-
responseMsg = NewMessage(Error{Message: []byte("Chain error: block header verification failure: InvalidTicketsMark")})
144-
// responseMsg = NewMessage(Error{Message: []byte("Chain error: block verification failure: invalid tickets mark")}) //fauty vectors have the error in different format
145-
} else if strings.Contains(err.Error(), "core unauthorized") {
146-
responseMsg = NewMessage(Error{Message: []byte("Chain error: block execution failure: reports error: code unauthorized")})
147-
} else if strings.Contains(err.Error(), "future report slot") {
148-
responseMsg = NewMessage(Error{Message: []byte("Chain error: block execution failure: reports error: report refers to slot in the future")})
149-
} else {
150-
return
151-
}
130+
responseMsg = NewMessage(Error{Message: []byte(fmt.Sprintf("Chain error: %s", err.Error()))})
152131
}
153132
respMsgBytes, err := jam.Marshal(responseMsg)
154133
if err != nil {
@@ -188,7 +167,7 @@ func (n *Node) messageHandler(msg *Message) (*Message, error) {
188167
return nil, fmt.Errorf("failed to import block: %v", err)
189168
}
190169

191-
if n.PeerInfo.FuzzFeatures == FeatureAncestryAndFork {
170+
if n.PeerInfo.FuzzFeatures == FeatureAncestry || n.PeerInfo.FuzzFeatures == FeatureAncestryAndFork {
192171
ancestry := choice.Ancestry
193172
for _, item := range ancestry.Items {
194173
err := n.chain.PutConformanceHeader(item.Hash, item.Slot)
@@ -197,7 +176,7 @@ func (n *Node) messageHandler(msg *Message) (*Message, error) {
197176
}
198177
}
199178
}
200-
stateRoot, err := merkle.MerklizeState(state, n.trie)
179+
stateRoot, err := merkle.MerklizeStateOnly(state)
201180
if err != nil {
202181
return nil, fmt.Errorf("failed to merklize state: %v", err)
203182
}
@@ -226,7 +205,7 @@ func (n *Node) messageHandler(msg *Message) (*Message, error) {
226205
if err != nil {
227206
return nil, fmt.Errorf("failed to import block: %v", err)
228207
}
229-
stateRoot, err := merkle.MerklizeState(state, n.trie)
208+
stateRoot, err := merkle.MerklizeStateOnly(state)
230209
if err != nil {
231210
return nil, fmt.Errorf("failed to import block: %v", err)
232211
}

0 commit comments

Comments
 (0)