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

Add report structs #29

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions internal/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ type Extrinsic struct {
EP *PreimageExtrinsic
ED *DisputeExtrinsic
EA *AssurancesExtrinsic
EG *GuaranteesExtrinsic
}
85 changes: 85 additions & 0 deletions internal/block/guarantee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package block

import (
"github.com/eigerco/strawberry/internal/crypto"
"github.com/eigerco/strawberry/internal/time"
)

// WorkResultError represents the type of error that occurred during work execution
type WorkResultError int

// WorkResultError represents the possible errors for a work result
const (
NoError WorkResultError = iota
OutOfGas // ∞: Out of gas error
Panic // ☇: Panic error
BadCode // BAD: Service's code not available
CodeTooLarge // BIG: Code available but exceeds maximum size
)

// GuaranteesExtrinsic represents the E_G extrinsic
type GuaranteesExtrinsic struct {
Guarantees []Guarantee
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	Guarantees [NrOfCores]Guarantee

Where:

const NrOfCores = 341

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same question as with Credential, do we need this intermediary struct GuaranteesExtrinsic or can we use []Guarantees directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is variable length, so we can't represent it and array with length 341.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this intermediary struct

I think so. I initially started the ticket with just a slice, but seems wrong and I have a PR fixing that. We will probably have functions specific for extrinsics, i.e. validate etc. So it makes sense.

}

// Guarantee represents a single guarantee within the E_G extrinsic
type Guarantee struct {
CoreIndex uint32 // Index of the core this guarantee is for
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding of the paper the core index is taken from the WorkReport.CoreIndex so defining it here is redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The paper defines it that way. Not sure about the reason for this redundancy, maybe somewhere we will take this index without the need to deserialize the work report. Gavin knows for sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the paper the EG is defined as a tuple of 3 items, core index is not one of them
image

WorkReport WorkReport // The work report being guaranteed
Credential Credential // The credential proving the guarantee's validity
Timeslot time.Timeslot // The timeslot when this guarantee was made
}

// Credential represents the credential a in the document
type Credential struct {
Signatures []CredentialSignature
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not trying to nitpick, but should we use []CredentialSignature directly in the Guarantee struct and rename CredentialSignature to Signature? we do we need to create this intermediary struct Credential?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Signatures is correct, because you get them from a Credential struct, so: Credential.Signatures, instead of Credential.CredentialSignatures.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question is not as much regarding the naming, as if we need this Credential struct at all and if we should use the sequence of signatures in the parent struct directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry didn't read correctly. Yeah, doesn't make sense. I'll update it, thanks!

}

// CredentialSignature represents a single signature within the credential
type CredentialSignature struct {
ValidatorIndex uint32 // Index of the validator providing this signature
Signature [crypto.Ed25519SignatureSize]byte // The Ed25519 signature
}

// WorkReport represents a report of completed work
type WorkReport struct {
Specification WorkPackageSpecification
Context RefinementContext
CoreIndex uint16 // N_C
AuthorizerHash crypto.Hash // H
Output []byte // Y a set of octet strings
Results []WorkResult // r ∈ ⟦L⟧_1:I: Sequence of 1 to I work results
}

// WorkPackageSpecification defines the specification of a work package
type WorkPackageSpecification struct {
Hash crypto.Hash // h ∈ H: Work package hash
Length uint32 // l ∈ N_L: Auditable work bundle length (N_L is the set of blob length values)
ErasureRoot crypto.Hash // u ∈ H: Erasure root
SegmentRoot crypto.Hash // e ∈ H: Segment root
}

// RefinementContext provides context for the refinement process
type RefinementContext struct {
AnchorHeaderHash crypto.Hash // a ∈ H: Anchor header hash
AnchorPosteriorStateRoot crypto.Hash // s ∈ H: Anchor state root
AnchorPosteriorBeefyRoot crypto.Hash // b ∈ H: Anchor Beefy root
LookupAnchorHeaderHash crypto.Hash // l ∈ H: Lookup anchor hash
LookupAnchorTimeslot time.Timeslot // t ∈ N_T: Lookup anchor timeslot
PrerequisiteHash *crypto.Hash // p ∈ H?: Optional prerequisite work package hash
}

// WorkResult represents the result of a single work item
type WorkResult struct {
ServiceIndex uint32 // s ∈ N_S: Service index (N_S is the set of service indices)
CodeHash crypto.Hash // c ∈ H: Code hash
PayloadHash crypto.Hash // l ∈ H: Payload hash
GasRatio uint64 // g ∈ N_G: Gas prioritization ratio
Output WorkResultOutput // o ∈ Y ∪ J: Output or error (Y is the set of octet strings, J is the set of work execution errors)
}

// WorkResultOutput represents either the successful output or an error from a work result
type WorkResultOutput struct {
Data []byte // Represents successful output (Y)
Error WorkResultError // Represents error output (J)
}