You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Header abstracts all methods required to perform header sync.typeHeaderinterface {
// New creates new instance of a header.New() Header// Hash returns hash of a header.Hash() Hash// Height returns the height of a header.Height() int64// LastHeader returns the hash of last header before this header (aka. previous header hash).LastHeader() Hash// Time returns time when header was created.Time() time.Time// IsRecent checks if header is recent against the given blockTime.IsRecent(duration time.Duration) bool// IsExpired checks if header is expired against trusting period.IsExpired() bool// VerifyAdjacent validates adjacent untrusted header against trusted header.VerifyAdjacent(Header) error// VerifyNonAdjacent validates non-adjacent untrusted header against trusted header.VerifyNonAdjacent(Header) error// Verify performs basic verification of untrusted header.Verify(Header) error// Validate performs basic validation to check for missed/incorrect fields.Validate() error
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
}
@tzdybal could you add some details as to why this is needed? I am missing the full context.
some functions in Header interface already exists, e.g., Hash() in types/hashing.go and MarshalBinary & UnmarshalBinary in types/serialization.go. we don't need to move them under the same file right? we can simply implement rest of the functions in e.g., header.go under types/header.go?
where can i read the specification for some of the functions like Verify, VerifyAdjacent, etc? or could you add some clarifying details as what they are expected to do?
@tzdybal could you add some details as to why this is needed? I am missing the full context.
This Header interface is a generic interface that will be used by https://github.com/celestiaorg/go-header/. This will be the common logic used to execute header sync in both celestia-node and rollmint light clients. Additionally we will need this interface to allow different headers implementations (for optimistic rollups, ZK rollups), and to enable users creating their own implementations.
2. some functions in Header interface already exists, e.g., `Hash()` in `types/hashing.go` and `MarshalBinary & UnmarshalBinary` in `types/serialization.go`. we don't need to move them under the same file right? we can simply implement rest of the functions in e.g., `header.go` under `types/header.go`?
Yes. We can simply implement the rest of the functions, without moving the existing ones. Note: I think that ValidateBasic can be simpy renamed to Validate.
3. where can i read the specification for some of the functions like `Verify`, `VerifyAdjacent`, etc? or could you add some clarifying details as what they are expected to do?
also, VerifyNonAdjacent requires Ensure that untrusted commit has enough of trusted commit's power. without the store, it is not possible to get access to ValidatorSet or Commits. any ideas on how to cover this? @tzdybal
New should create new instance of concrete type implementing the interface. Context: when deserializing we need actual object of given type, like:
varobjHobj.UnmarshalBinary(data)
where H is generic type of header.Header interface. This won't work unfortunately, as default value for pointers is nil so deserialization will panic. And most probably interface will be implemented for pointer receiver.
The "hack" to mitigate this without using reflection, with construct like:
Yes, right now we have Height and Time as fields, but we need to refactor this. Because interfaces cannot define fields, and we need an universal method of accessing Height and Time in header library.
Sorry for that - I just copy-pasted the comment from Node implementation, and it makes no sense 🤦 This method definitely work without accessing store.
https://github.com/celestiaorg/go-header seems like not ready, should the rollmint repo add go-header as dependency and use Header interface definition? The Hash type seems to be missing.
Throughout rollmint [32]byte is used where as celestia-core uses tmbytes.HexBytes and the generic header interface planning to use a new type Hash. May be we should make these uniform across?
My PR replaces HexBytes in node, as it's completely unnecessary. For now, you can copy the hash definition, just like you copied Header interface. We'll refactor this when go-header is ready.
Yes it should return empty instance of our Header, as you mentioned 👍
also, VerifyNonAdjacent requires Ensure that untrusted commit has enough of trusted commit's power. without the store, it is not possible to get access to ValidatorSet or Commits. any ideas on how to cover this?
you could give it the validator set as an argument along with a merkle proof to the previous header's root
Activity
gupadhyaya commentedon Dec 1, 2022
Hash()intypes/hashing.goandMarshalBinary & UnmarshalBinaryintypes/serialization.go. we don't need to move them under the same file right? we can simply implement rest of the functions in e.g.,header.goundertypes/header.go?Verify,VerifyAdjacent, etc? or could you add some clarifying details as what they are expected to do?tzdybal commentedon Dec 1, 2022
This
Headerinterface is a generic interface that will be used by https://github.com/celestiaorg/go-header/. This will be the common logic used to execute header sync in both celestia-node and rollmint light clients. Additionally we will need this interface to allow different headers implementations (for optimistic rollups, ZK rollups), and to enable users creating their own implementations.Yes. We can simply implement the rest of the functions, without moving the existing ones. Note: I think that
ValidateBasiccan be simpy renamed toValidate.Unfortunately there is no documentation yet. The best you can get is to look at implementation in node - and at the same time, I'll work on creating godocs for all those methods.
https://github.com/celestiaorg/celestia-node/blob/da4f54bca1bfef86f53880ced569d37ffb4b8b84/header/verify.go#L36
https://github.com/celestiaorg/celestia-node/blob/da4f54bca1bfef86f53880ced569d37ffb4b8b84/header/verify.go#L51
gupadhyaya commentedon Dec 5, 2022
@tzdybal
Newshould create emptyHeaderor something similar to clone?Headertype has filedsHeightandTime, are the interface methods necessary? Also it doesn't allow duplicate field and interface methodgupadhyaya commentedon Dec 5, 2022
also,
VerifyNonAdjacentrequiresEnsure that untrusted commit has enough of trusted commit's power.without the store, it is not possible to get access toValidatorSetorCommits. any ideas on how to cover this? @tzdybaltzdybal commentedon Dec 5, 2022
Newshould create new instance of concrete type implementing the interface. Context: when deserializing we need actual object of given type, like:where
His generic type ofheader.Headerinterface. This won't work unfortunately, as default value for pointers isnilso deserialization will panic. And most probably interface will be implemented for pointer receiver.The "hack" to mitigate this without using reflection, with construct like:
Yes, right now we have
HeightandTimeas fields, but we need to refactor this. Because interfaces cannot define fields, and we need an universal method of accessingHeightandTimein header library.Sorry for that - I just copy-pasted the comment from Node implementation, and it makes no sense 🤦 This method definitely work without accessing store.
gupadhyaya commentedon Dec 6, 2022
@tzdybal few more questions:
Hashtype seems to be missing.[32]byteis used where as celestia-core usestmbytes.HexBytesand the generic header interface planning to use a new typeHash. May be we should make these uniform across?Newmethod. Should it not return an empty instance of https://github.com/celestiaorg/rollmint/blob/main/types/block.go#L10?I have a draft PR above and could you let me know if the direction i am taking is correct?
tzdybal commentedon Dec 6, 2022
header.Headerinterface celestiaorg/celestia-node#1304, I'll extract the code from celestia-node to go-header (again), and we'll be able to add it as dependency for rollmint.HexBytesin node, as it's completely unnecessary. For now, you can copy the hash definition, just like you copiedHeaderinterface. We'll refactor this when go-header is ready.Header, as you mentioned 👍S1nus commentedon Jan 11, 2023
you could give it the validator set as an argument along with a merkle proof to the previous header's root
Integration with go-header (#685)