-
Notifications
You must be signed in to change notification settings - Fork 4
Serializable messages and generic operations #467
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
base: main
Are you sure you want to change the base?
Conversation
|
👋 krebernisak, thanks for creating this pull request! To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team. Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces serializable message envelopes and generic operations for TON blockchain interactions, reorganizing the codebase to support better message handling and codec functionality.
Key changes:
- Introduced a generic message envelope system with JSON serialization support
- Created a custom JSON codec for TL-B message structures
- Moved debug-related code from
pkg/ton/debugtopkg/ton/codec/debugfor better organization - Added operations framework for message planning and execution
Reviewed changes
Copilot reviewed 69 out of 79 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/ton/tvm/registry.go | Adds TLB map registry for message type lookups |
| pkg/ton/tvm/magic.go | Implements magic number extraction from TL-B structs |
| pkg/ton/codec/envelope.go | Introduces generic MessageEnvelope for type-safe message handling |
| pkg/ton/codec/jsoncodec/codec.go | Implements custom JSON codec for TL-B structures |
| pkg/ton/codec/decoder.go | Refactors decoder to use new TLB registry types |
| pkg/ton/tlbe/dictionary.go | Adds generic dictionary wrapper for TL-B dictionaries |
| pkg/ton/tlbe/biguint.go | Adds BitsLen methods and Cmp for Uint256 |
| pkg/bindings/*.go | Updates all bindings to add json:"-" tags to Magic fields and use new registry |
| deployment/pkg/ops/*.go | Adds operations framework for message planning and execution |
| deployment/pkg/utils/generator.go | Adds sample data generator for testing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Amount *big.Int `tlb:"## 256"` | ||
| Token address.Address `tlb:"addr"` | ||
| Amount *big.Int `tlb:"## 256"` | ||
| Token *address.Address `tlb:"addr"` |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing Token from address.Address to *address.Address is a breaking change. This makes the field nullable which could impact existing code that assumes this field is always present.
| // Any2TVMMessage represents a cross-chain message to TON | ||
| type Any2TVMMessage struct { | ||
| MessageID [32]byte `tlb:"bits 256"` | ||
| MessageID []byte `tlb:"bits 256"` |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing MessageID from [32]byte to []byte removes compile-time size guarantees. This is a breaking change that could lead to runtime errors if the slice doesn't have exactly 32 bytes.
| MessageID []byte `tlb:"bits 256"` | |
| MessageID [32]byte `tlb:"bits 256"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using [32byte fails with panic: reflect.Value.Bytes of unaddressable byte array [recovered, repanicked], works as:
[]byte- current choice*[32]byte
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can at least leave a comment clarifying it is 32 bytes? Should we create a wrapper type instead maybe?
| // NewGenerator constructs a Generator with sensible defaults. | ||
| func NewGenerator(opts ...Option) *Generator { | ||
| g := &Generator{ | ||
| rng: rand.New(rand.NewSource(42)), |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a fixed seed (42) for random number generation makes the output predictable. While this may be intentional for testing, consider documenting this behavior and providing an option to use a secure random seed for production use cases.
| if t.Kind() == reflect.Pointer { | ||
| inst = reflect.New(t.Elem()).Interface().(DictKey) | ||
| } else { | ||
| inst = reflect.New(t).Elem().Interface().(DictKey) |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type assertion without checking can panic. Wrap this in a type assertion with the ok pattern to handle cases where the type doesn't implement DictKey.
| } | ||
|
|
||
| // Sent back to sender after the executor role check is updated. | ||
| type TestMessage struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: move to tests
| // Any2TVMMessage represents a cross-chain message to TON | ||
| type Any2TVMMessage struct { | ||
| MessageID [32]byte `tlb:"bits 256"` | ||
| MessageID []byte `tlb:"bits 256"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using [32byte fails with panic: reflect.Value.Bytes of unaddressable byte array [recovered, repanicked], works as:
[]byte- current choice*[32]byte
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really promising! Left some small comments
| if field != nil { | ||
| ctx.Tag = parseTLBTag(field.Tag.Get("tlb")) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this duplicated above?
|
|
||
| size := g.randomCollectionSize() | ||
| slice := reflect.MakeSlice(t, size, size) | ||
| for i := 0; i < size; i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
| for i := 0; i < size; i++ { | |
| for i := range size { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move tests to a different module so we don't ship them in the package?
| // Any2TVMMessage represents a cross-chain message to TON | ||
| type Any2TVMMessage struct { | ||
| MessageID [32]byte `tlb:"bits 256"` | ||
| MessageID []byte `tlb:"bits 256"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can at least leave a comment clarifying it is 32 bytes? Should we create a wrapper type instead maybe?
tlbe.Dict[K, V]to replacecell.Dictionaryas a JSON/Cell serializable generic (dict) typetlbe.ToCell/LoadFromCellshims to support int/uint primitive types (avoid needing a wrapper type for these)_ tlb.Magicstruct opcodes with<tlb:...> json:"-"to make those structs pass CLDF'soperations.IsSerializablecheckcodec.MessageEnvelope[T]which is a JSON/Cell serializable generic (message wrapper) typetvm.MessageRegistryto map contract types (string) to their corresponding TLBMap (opcode -> msg)ops.SendMessages[T]operation - standardizes sending any[]codec.MessageEnvelope[T]batch (+ metadata) on inputops.AnySequencesequence - standardizes sequencing of any operation based on input (e.g.,ops.SendMessageabove)pkg/ton/codecand restructure/rm the existingpkg/ton/debugpackage