Skip to content

Conversation

@StephenButtolph
Copy link
Contributor

@StephenButtolph StephenButtolph commented Aug 15, 2025

Why this should be merged

  1. This adds explicit tests of the serialization format. This is important because any changes to the serialization format (even if they are symmetric between Parse and Bytes) could break existing logic.
  2. This removes the usage of structs to instead prefer using the maps directly (which the reflect codec fully supports).
  3. This aligns the behavior of Set and Get where after Seting a zero value, Get behaves the same as if the value was never set.
  4. This aligns the behavior that Set had previously (which is required to remain compatible with the C-chain's block building logic)

How this works

Updated logic to better align with coreth and improved the tests to fully verify the behaviors we expect.

How this was tested

Unit tests

Need to be documented in RELEASES.md?

No.

if result, ok := (*b)[txHash][address]; ok {
return result
}
return set.NewBits()
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 zero value of set.Bits is not safe to use afaict

Comment on lines +78 to +80
if len(txResults) == 0 {
delete(*b, txHash)
return
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to be done to work with the coreth/subnet-evm block building logic.

type encodedBlockResults struct {
TxResults map[common.Hash]map[common.Address][]byte `serialize:"true"`
return resultsCodec.Marshal(version, encoded)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to wrap this into a type (and removing the type wrapper doesn't change the serialization format)

common.Address{2}: set.NewBits(1, 2, 3),
},
},
want: []byte{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Explicitly locking in the serialization format makes me a lot more comfortable to make changes here.

{2}: {
{2}: set.NewBits(1, 2, 3),
{3}: set.NewBits(3, 2, 1),
name: "delete_tx",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need this case to support Delete like it had before.

Comment on lines +411 to +413
parsed, err := ParseBlockResults(got)
require.NoError(err)
require.Equal(input, parsed)
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 thought about moving this out to a separate test... But I felt like it was overly repetitive.

Copy link
Contributor

Copilot AI left a 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 improves the handling of predicate results by refactoring the data structures and enhancing test coverage for serialization. The changes focus on making the API more consistent and ensuring proper handling of zero values.

  • Refactored BlockResults from a struct with a TxResults field to a direct type alias for better API consistency
  • Enhanced the Get method to always return a valid set.Bits instead of a boolean-checked tuple
  • Improved the Set method to properly handle zero values by deleting empty entries

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
vms/evm/predicate/results.go Refactored BlockResults type from struct to map alias and updated method signatures for consistency
vms/evm/predicate/results_test.go Added comprehensive serialization tests and restructured existing tests to verify new behaviors
vms/evm/predicate/predicate_test.go Updated test helpers to use generic set types instead of custom allowSet type

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@StephenButtolph StephenButtolph merged commit 555dd51 into uplift-evm-predicate Aug 15, 2025
29 checks passed
@StephenButtolph StephenButtolph deleted the simplify-results-handling branch August 15, 2025 21:29
@github-project-automation github-project-automation bot moved this to Done 🎉 in avalanchego Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants