Skip to content

Commit

Permalink
Switch to typeconv.AddressBytesToString.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Aug 22, 2024
1 parent 283bdb8 commit f38840d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
5 changes: 3 additions & 2 deletions execute/exectypes/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ type CommitObservations map[cciptypes.ChainSelector][]CommitData
// and sequence number.
type MessageObservations map[cciptypes.ChainSelector]map[cciptypes.SeqNum]cciptypes.Message

// NonceObsservations contain the latest nonce for senders in the previously observed messages.
// Nonces are organized by source chain selector and the string encoded sender address.
// NonceObservations contain the latest nonce for senders in the previously observed messages.
// Nonces are organized by source chain selector and the string encoded sender address. The address
// must be encoding according to the destination chain requirements with typeconv.AddressBytesToString.
type NonceObservations map[cciptypes.ChainSelector]map[string]uint64

// Observation is the observation of the ExecutePlugin.
Expand Down
35 changes: 12 additions & 23 deletions execute/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/smartcontractkit/chainlink-ccip/execute/exectypes"
"github.com/smartcontractkit/chainlink-ccip/execute/internal/gas"
"github.com/smartcontractkit/chainlink-ccip/execute/report"
typeconv "github.com/smartcontractkit/chainlink-ccip/internal/libs/typeconv"
"github.com/smartcontractkit/chainlink-ccip/internal/plugincommon"
"github.com/smartcontractkit/chainlink-ccip/internal/reader"
"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
Expand Down Expand Up @@ -255,7 +256,8 @@ func (p *Plugin) Observation(
nonceRequestArgs[commitReport.SourceChainSelector] = make(map[string]struct{})
}
for _, msg := range commitReport.Messages {
nonceRequestArgs[commitReport.SourceChainSelector][msg.Sender.String()] = struct{}{}
sender := typeconv.AddressBytesToString(msg.Sender[:], uint64(p.cfg.DestChain))
nonceRequestArgs[commitReport.SourceChainSelector][sender] = struct{}{}
}
}

Expand Down Expand Up @@ -313,30 +315,13 @@ func (p *Plugin) ObservationQuorum(outctx ocr3types.OutcomeContext, query types.
// If there is not enough space in the final report, it may be partially executed by searching for a subset of messages
// which can fit in the final report.
func selectReport(
ctx context.Context,
lggr logger.Logger,
hasher cciptypes.MessageHasher,
encoder cciptypes.ExecutePluginCodec,
tokenDataReader exectypes.TokenDataReader,
estimateProvider gas.EstimateProvider,
nonces map[cciptypes.ChainSelector]map[string]uint64,
commitReports []exectypes.CommitData,
maxReportSizeBytes int,
maxGas uint64,
builder report.ExecReportBuilder,
) ([]cciptypes.ExecutePluginReportSingleChain, []exectypes.CommitData, error) {
// TODO: It may be desirable for this entire function to be an interface so that
// different selection algorithms can be used.

builder := report.NewBuilder(
ctx,
lggr,
hasher,
tokenDataReader,
encoder,
estimateProvider,
nonces,
uint64(maxReportSizeBytes),
maxGas)
var stillPendingReports []exectypes.CommitData
for i, report := range commitReports {
// Reports at the end may not have messages yet.
Expand Down Expand Up @@ -458,17 +443,21 @@ func (p *Plugin) Outcome(
commitReports := previousOutcome.PendingCommitReports

// TODO: this function should be pure, a context should not be needed.
outcomeReports, commitReports, err := selectReport(
builder := report.NewBuilder(
context.Background(),
p.lggr,
p.msgHasher,
p.reportCodec,
p.tokenDataReader,
p.reportCodec,
p.estimateProvider,
observation.Nonces,
commitReports,
maxReportSizeBytes,
p.cfg.DestChain,
uint64(maxReportSizeBytes),
p.cfg.OffchainConfig.BatchGasLimit)
outcomeReports, commitReports, err := selectReport(
p.lggr,
commitReports,
builder)
if err != nil {
return ocr3types.Outcome{}, fmt.Errorf("unable to extract proofs: %w", err)
}
Expand Down
3 changes: 3 additions & 0 deletions execute/report/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func NewBuilder(
encoder cciptypes.ExecutePluginCodec,
estimateProvider gas.EstimateProvider,
nonces map[cciptypes.ChainSelector]map[string]uint64,
destChainSelector cciptypes.ChainSelector,
maxReportSizeBytes uint64,
maxGas uint64,
) ExecReportBuilder {
Expand All @@ -41,6 +42,7 @@ func NewBuilder(
sendersNonce: nonces,
expectedNonce: make(map[cciptypes.ChainSelector]map[string]uint64),

destChainSelector: destChainSelector,
maxReportSizeBytes: maxReportSizeBytes,
maxGas: maxGas,
}
Expand Down Expand Up @@ -71,6 +73,7 @@ type execReportBuilder struct {
sendersNonce map[cciptypes.ChainSelector]map[string]uint64

// Config
destChainSelector cciptypes.ChainSelector
maxReportSizeBytes uint64
maxGas uint64

Expand Down
3 changes: 2 additions & 1 deletion execute/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/smartcontractkit/chainlink-ccip/execute/exectypes"
"github.com/smartcontractkit/chainlink-ccip/internal/libs/slicelib"
typeconv "github.com/smartcontractkit/chainlink-ccip/internal/libs/typeconv"
)

// buildSingleChainReportHelper converts the on-chain event data stored in cciptypes.ExecutePluginCommitData into the
Expand Down Expand Up @@ -226,7 +227,7 @@ func (b *execReportBuilder) checkMessage(
}

chainNonces := b.sendersNonce[execReport.SourceChain]
sender := msg.Sender.String()
sender := typeconv.AddressBytesToString(msg.Sender[:], uint64(b.destChainSelector))
if _, ok := chainNonces[sender]; !ok {
b.lggr.Errorw("Skipping message - missing nonce",
"messageID", msg.Header.MessageID,
Expand Down
3 changes: 2 additions & 1 deletion internal/reader/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ type CCIP interface {
// TODO: if destination was a parameter, this could be a capability reused across plugin instances.
NextSeqNum(ctx context.Context, chains []cciptypes.ChainSelector) (seqNum []cciptypes.SeqNum, err error)

// Nonces fetches all nonces for the provided selector/address pairs. Addresses are a string encoded raw address.
// Nonces fetches all nonces for the provided selector/address pairs. Addresses are a string encoded raw address,
// it must be encoding according to the destination chain requirements with typeconv.AddressBytesToString.
Nonces(
ctx context.Context,
source, dest cciptypes.ChainSelector,
Expand Down

0 comments on commit f38840d

Please sign in to comment.