Skip to content

Commit

Permalink
revert bad merge to main; workflow.go, cap_encoder*
Browse files Browse the repository at this point in the history
  • Loading branch information
krehermann committed Jan 10, 2025
1 parent 8bbd762 commit 0db7346
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 118 deletions.
1 change: 0 additions & 1 deletion core/capabilities/integration_tests/keystone/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ consensus:
encoder: "EVM"
encoder_config:
abi: "(bytes32 FeedID, uint224 Price, uint32 Timestamp)[] Reports"
subabi: 'map[string]string{"Reports.Price": "uint224 Price"}'
targets:
- id: "[email protected]"
Expand Down
36 changes: 8 additions & 28 deletions core/services/relay/evm/cap_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import (
)

const (
abiConfigFieldName = "abi"
subabiConfigFieldName = "subabi"
subabi2ConfigFieldName = "subabi2"
encoderName = "user"
abiConfigFieldName = "abi"
subabiConfigFieldName = "subabi"
encoderName = "user"
)

type capEncoder struct {
Expand Down Expand Up @@ -53,8 +52,6 @@ func NewEVMEncoder(config *values.Map) (consensustypes.Encoder, error) {
TypeABI: string(jsonSelector),
}

var modifierConfigs commoncodec.ModifiersConfig

var subabi map[string]string
subabiConfig, ok := config.Underlying[subabiConfigFieldName]
if ok {
Expand All @@ -66,31 +63,14 @@ func NewEVMEncoder(config *values.Map) (consensustypes.Encoder, error) {
if err2 != nil {
return nil, err2
}
modifierConfigs = append(modifierConfigs, &commoncodec.PreCodecModifierConfig{
Fields: subabi,
Codecs: codecs,
})
}

var subabi2 map[string]string
subabiConfig2, ok := config.Underlying[subabi2ConfigFieldName]
if ok {
err2 := subabiConfig2.UnwrapTo(&subabi2)
if err2 != nil {
return nil, err2
}
codecs2, err2 := makePreCodecModifierCodecs(subabi2)
if err2 != nil {
return nil, err2
chainCodecConfig.ModifierConfigs = commoncodec.ModifiersConfig{
&commoncodec.PreCodecModifierConfig{
Fields: subabi,
Codecs: codecs,
},
}
modifierConfigs = append(modifierConfigs, &commoncodec.PreCodecModifierConfig{
Fields: subabi2,
Codecs: codecs2,
})
}

chainCodecConfig.ModifierConfigs = modifierConfigs

codecConfig := types.CodecConfig{Configs: map[string]types.ChainCodecConfig{
encoderName: chainCodecConfig,
}}
Expand Down
89 changes: 0 additions & 89 deletions core/services/relay/evm/cap_encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,84 +289,6 @@ func TestEVMEncoder_SubABI(t *testing.T) {
require.Equal(t, expected, hex.EncodeToString(encoded))
}

func TestEVMEncoder_SubABI2(t *testing.T) {
config := map[string]any{
"abi": "(bytes Report)[] Reports",
"subabi2": map[string]string{
"Reports.Report.Bundle": "uint256 Ask, uint256 Bid",
},
"subabi": map[string]string{
"Reports.Report": "bytes32 FeedID, bytes Bundle, uint32 Timestamp",
},
}
wrapped, err := values.NewMap(config)
require.NoError(t, err)
enc, err := evm.NewEVMEncoder(wrapped)
require.NoError(t, err)

type SubReport struct {
Ask int
Bid int
}
type ReportStruct struct {
FeedID [32]byte
Bundle SubReport
Timestamp uint32
}
type ReportWrapper struct {
Report ReportStruct
}
reportOne := ReportWrapper{Report: ReportStruct{
FeedID: [32]byte{1},
Bundle: SubReport{
Ask: 1,
Bid: 2,
},
Timestamp: 47890122,
}}
reportTwo := ReportWrapper{Report: ReportStruct{
FeedID: [32]byte{2},
Bundle: SubReport{
Ask: 3,
Bid: 4,
},
Timestamp: 47890122,
}}

// output of a reduce aggregator + metadata fields appended by OCR
input := map[string]any{
"Reports": []any{reportOne, reportTwo},
consensustypes.MetadataFieldName: getMetadata(workflowID),
}
wrapped, err = values.NewMap(input)
require.NoError(t, err)
encoded, err := enc.Encode(testutils.Context(t), *wrapped)
require.NoError(t, err)

expected :=
// start of the outer tuple
getHexMetadata() +
// start of the inner tuple (user_fields)
"0000000000000000000000000000000000000000000000000000000000000020" + // offset of Reports array
"0000000000000000000000000000000000000000000000000000000000000002" + // length of Reports array
"0000000000000000000000000000000000000000000000000000000000000040" + // offset of ReportOne
"0000000000000000000000000000000000000000000000000000000000000100" + // offset of ReportTwo
"0100000000000000000000000000000000000000000000000000000000000000" + // ReportOne FeedID
"0000000000000000000000000000000000000000000000000000000000000060" + // offset of ReportOne Bundle
"0000000000000000000000000000000000000000000000000000000002dabeca" + // ReportOne Timestamp
"0000000000000000000000000000000000000000000000000000000000000040" + // length of ReportOne Bundle
"0000000000000000000000000000000000000000000000000000000000000005" + // ReportOne Ask
"0000000000000000000000000000000000000000000000000000000000000006" + // ReportOne Bid
"0200000000000000000000000000000000000000000000000000000000000000" + // ReportTwo FeedID
"0000000000000000000000000000000000000000000000000000000000000060" + // offset of ReportTwo Bundle
"0000000000000000000000000000000000000000000000000000000002dabeca" + // ReportTwo Timestamp
"0000000000000000000000000000000000000000000000000000000000000040" + // length of ReportTwo Bundle
"0000000000000000000000000000000000000000000000000000000000000007" + // ReportTwo Ask
"0000000000000000000000000000000000000000000000000000000000000008" // ReportTwo Bid

require.Equal(t, expected, hex.EncodeToString(encoded))
}

func getHexMetadata() string {
return "01" + executionID + timestampHex + donIDHex + configVersionHex + workflowID + workflowName + workflowOwnerID + reportID
}
Expand All @@ -384,14 +306,3 @@ func getMetadata(cid string) consensustypes.Metadata {
ReportID: reportID,
}
}

//0000000000000000000000000000000000000000000000000000000000000020 // offset of Reports array
//0000000000000000000000000000000000000000000000000000000000000001 // length of Reports array
//0000000000000000000000000000000000000000000000000000000000000020 // offset of ReportOne
//018bfe8840700040000000000000000000000000000000000000000000000000
//000000000000000000000000000000000000000000000000000000006764774b
//0000000000000000000000000000000000000000000000000000000000000060
//0000000000000000000000000000000000000000000000000000000000000020
//0000000000000000000000000000000000000000000000000000000bb5c162c8

"0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000100010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000002dabeca000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000002dabeca000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000008" // ReportTwo Bid

0 comments on commit 0db7346

Please sign in to comment.