Skip to content
Merged
Changes from 10 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3e73f11
Updated ocr3 Metadata type to include Encoding and Decoding
silaslenihan Apr 25, 2025
0b88e24
Merge branch 'main' into update-ocr3-metadata
silaslenihan Apr 30, 2025
ea228d8
Merge branch 'main' into update-ocr3-metadata
silaslenihan May 7, 2025
1ef8a0f
Merge branch 'main' into update-ocr3-metadata
silaslenihan May 13, 2025
b60cf42
Merge branch 'main' into update-ocr3-metadata
silaslenihan May 13, 2025
a973d22
Merge branch 'main' into update-ocr3-metadata
silaslenihan May 14, 2025
6cfaac2
Merge branch 'main' into update-ocr3-metadata
silaslenihan May 19, 2025
f3ed96e
Revert "add GetEstimateFee (#1196)"
silaslenihan May 19, 2025
3277762
Reapply "add GetEstimateFee (#1196)"
silaslenihan May 20, 2025
d8e352f
Merge branch 'main' into update-ocr3-metadata
silaslenihan May 23, 2025
46548a5
addressed feedback
silaslenihan May 23, 2025
9aa700e
Merge branch 'main' into update-ocr3-metadata
silaslenihan May 27, 2025
5ca7af8
Moved proto emitter and helpers to common
silaslenihan May 27, 2025
7d73232
Published common attritutes
silaslenihan May 27, 2025
acf7933
addressed feedback
silaslenihan May 28, 2025
630467f
Merge branch 'main' into update-ocr3-metadata
silaslenihan May 28, 2025
9084a34
Merge branch 'main' into update-ocr3-metadata
silaslenihan May 30, 2025
4563985
Merge branch 'main' into update-ocr3-metadata
silaslenihan Jun 3, 2025
a99824a
added beholder attribute data_type
silaslenihan Jun 3, 2025
6bd2efa
Merge branch 'main' into update-ocr3-metadata
silaslenihan Jun 4, 2025
55281bb
Merge branch 'main' into update-ocr3-metadata
silaslenihan Jun 4, 2025
f63d042
Merge branch 'main' into update-ocr3-metadata
silaslenihan Jun 5, 2025
64c6a47
removed behodler for attr keys'
silaslenihan Jun 5, 2025
bc72ed9
Merge branch 'main' into update-ocr3-metadata
silaslenihan Jun 5, 2025
1ff9a46
Revert "pkg/loop: expand EnvConfig and make available from Server (#1…
silaslenihan Jun 5, 2025
6dcd6de
Merge branch 'main' into update-ocr3-metadata
silaslenihan Jun 6, 2025
5981ca5
Reapply "pkg/loop: expand EnvConfig and make available from Server (#…
silaslenihan Jun 6, 2025
51de512
Merge branch 'main' into update-ocr3-metadata
silaslenihan Jun 9, 2025
54755c8
Revert "Seed random for setup and modes (#1236)"
silaslenihan Jun 10, 2025
491d1b2
Reapply "Seed random for setup and modes (#1236)"
silaslenihan Jun 10, 2025
d504298
Merge branch 'main' into update-ocr3-metadata
silaslenihan Jun 11, 2025
eb6b357
Merge branch 'main' into update-ocr3-metadata
silaslenihan Jun 11, 2025
00a1fdb
Revert "requests handling (#1247)"
silaslenihan Jun 11, 2025
938ff7f
Reapply "requests handling (#1247)"
silaslenihan Jun 11, 2025
e845ca6
Made ToSchemaFullName public
silaslenihan Jun 11, 2025
9f01f00
Merge branch 'main' into update-ocr3-metadata
silaslenihan Jun 17, 2025
fad1860
Merge branch 'main' into update-ocr3-metadata
silaslenihan Jun 17, 2025
e2cdf99
Merge branch 'main' into update-ocr3-metadata
silaslenihan Jun 18, 2025
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
149 changes: 149 additions & 0 deletions pkg/capabilities/consensus/ocr3/types/aggregator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package types

import (
"bytes"
"encoding/binary"
"encoding/hex"
"fmt"
"io"
"strings"

ocrcommon "github.com/smartcontractkit/libocr/commontypes"
Expand Down Expand Up @@ -34,6 +39,150 @@ func (m *Metadata) padWorkflowName() {
}
}

// Encode serializes Metadata in contract order:
// 1B Version, 32B ExecutionID, 4B Timestamp, 4B DONID, 4B DONConfigVersion,
// 32B WorkflowID, 10B WorkflowName, 20B WorkflowOwner, 2B ReportID
func (m Metadata) Encode() ([]byte, error) {
m.padWorkflowName()
buf := new(bytes.Buffer)

// 1) Version as a single byte
if err := buf.WriteByte(byte(m.Version)); err != nil {
return nil, err
}

// 2) Helper to decode a hex string and ensure length
writeHex := func(field string, expectedBytes int) error {
s := strings.TrimPrefix(field, "0x")
b, err := hex.DecodeString(s)
if err != nil {
return fmt.Errorf("invalid hex in field: %w", err)
}
if len(b) != expectedBytes {
return fmt.Errorf("wrong length: expected %d bytes, got %d", expectedBytes, len(b))
}
_, err = buf.Write(b)
return err
}

// ExecutionID: 32 bytes
if err := writeHex(m.ExecutionID, 32); err != nil {
return nil, fmt.Errorf("ExecutionID: %w", err)
}

// Timestamp, DONID, DONConfigVersion—all 4‐byte big endian
for _, v := range []uint32{m.Timestamp, m.DONID, m.DONConfigVersion} {
if err := binary.Write(buf, binary.BigEndian, v); err != nil {
return nil, err
}
}

// WorkflowID: 32 bytes
if err := writeHex(m.WorkflowID, 32); err != nil {
return nil, fmt.Errorf("WorkflowID: %w", err)
}

// Workflow Name: 10 bytes
if err := writeHex(m.WorkflowName, 10); err != nil {
return nil, fmt.Errorf("WorkflowName: %w", err)
}

// WorkflowOwner: 20 bytes
if err := writeHex(m.WorkflowOwner, 20); err != nil {
return nil, fmt.Errorf("WorkflowOwner: %w", err)
}

// ReportID: 2 bytes
if err := writeHex(m.ReportID, 2); err != nil {
return nil, fmt.Errorf("ReportID: %w", err)
}

return buf.Bytes(), nil
}

const MetadataLen = 1 + 32 + 4 + 4 + 4 + 32 + 10 + 20 + 2 // =109

// Decode parses exactly MetadataLen bytes from raw, returns a Metadata struct
// and any trailing data.
func Decode(raw []byte) (Metadata, []byte, error) {
m := Metadata{}

if len(raw) < MetadataLen {
return m, nil, fmt.Errorf("metadata: raw too short, want ≥%d, got %d", MetadataLen, len(raw))
}

buf := bytes.NewReader(raw[:MetadataLen])

// 1) Version (1 byte)
var vb byte
if err := binary.Read(buf, binary.BigEndian, &vb); err != nil {
return m, nil, err
}
m.Version = uint32(vb)

// helper to read N bytes and hex-decode
readHex := func(n int) (string, error) {
tmp := make([]byte, n)
if _, err := io.ReadFull(buf, tmp); err != nil {
return "", err
}
return hex.EncodeToString(tmp), nil
}

// 2) ExecutionID (32 bytes hex)
var err error
if m.ExecutionID, err = readHex(32); err != nil {
return m, nil, fmt.Errorf("ExecutionID: %w", err)
}

// 3) Timestamp, DONID, DONConfigVersion (each 4 bytes BE)
for _, ptr := range []*uint32{&m.Timestamp, &m.DONID, &m.DONConfigVersion} {
if err := binary.Read(buf, binary.BigEndian, ptr); err != nil {
return m, nil, err
}
}

// 4) WorkflowID (32 bytes hex)
if m.WorkflowID, err = readHex(32); err != nil {
return m, nil, fmt.Errorf("WorkflowID: %w", err)
}

nameBytes := make([]byte, 10)
if _, err := io.ReadFull(buf, nameBytes); err != nil {
return m, nil, err
}
// hex-encode those 10 bytes into a 20-char string
m.WorkflowName = hex.EncodeToString(nameBytes)

// 6) WorkflowOwner (20 bytes hex)
if m.WorkflowOwner, err = readHex(20); err != nil {
return m, nil, fmt.Errorf("WorkflowOwner: %w", err)
}

// 7) ReportID (2 bytes hex)
if m.ReportID, err = readHex(2); err != nil {
return m, nil, fmt.Errorf("ReportID: %w", err)
}

// strip any stray "0x" prefixes just in case
m.ExecutionID = strings.TrimPrefix(m.ExecutionID, "0x")
m.WorkflowID = strings.TrimPrefix(m.WorkflowID, "0x")
m.WorkflowOwner = strings.TrimPrefix(m.WorkflowOwner, "0x")
m.ReportID = strings.TrimPrefix(m.ReportID, "0x")

// the rest is payload
tail := raw[MetadataLen:]
return m, tail, nil
}

func (m Metadata) Length() int {
b, err := m.Encode()
if err != nil {
return 0
}
return len(b)
}

// Aggregator is the interface that enables a hook to the Outcome() phase of OCR reporting.
type Aggregator interface {
// Called by the Outcome() phase of OCR reporting.
Expand Down
Loading