Skip to content

Commit

Permalink
reduce redundant data storage
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Jul 15, 2024
1 parent 6876a78 commit dfdc827
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
41 changes: 28 additions & 13 deletions integration-tests/ccip-tests/actions/ccip_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2246,7 +2246,7 @@ func (destCCIP *DestCCIPModule) AssertNoExecutionStateChangedEventReceived(
destCCIP.ExecStateChangedWatcher.Range(func(_, value any) bool {
e, exists := value.(*contracts.EVM2EVMOffRampExecutionStateChanged)
if exists {
vLogs := e.Raw
vLogs := e.LogInfo
hdr, err := destCCIP.Common.ChainClient.HeaderByNumber(ctx, big.NewInt(int64(vLogs.BlockNumber)))
if err != nil {
return true
Expand Down Expand Up @@ -2292,7 +2292,7 @@ func (destCCIP *DestCCIPModule) AssertEventExecutionStateChanged(
if exists {
// if the value is processed, delete it from the map
destCCIP.ExecStateChangedWatcher.Delete(seqNum)
vLogs := e.Raw
vLogs := e.LogInfo
receivedAt := time.Now().UTC()
hdr, err := destCCIP.Common.ChainClient.HeaderByNumber(context.Background(), big.NewInt(int64(vLogs.BlockNumber)))
if err == nil {
Expand Down Expand Up @@ -2367,7 +2367,7 @@ func (destCCIP *DestCCIPModule) AssertEventReportAccepted(
// if the value is processed, delete it from the map
destCCIP.ReportAcceptedWatcher.Delete(seqNum)
receivedAt := time.Now().UTC()
hdr, err := destCCIP.Common.ChainClient.HeaderByNumber(context.Background(), big.NewInt(int64(reportAccepted.Raw.BlockNumber)))
hdr, err := destCCIP.Common.ChainClient.HeaderByNumber(context.Background(), big.NewInt(int64(reportAccepted.LogInfo.BlockNumber)))
if err == nil {
receivedAt = hdr.Timestamp
}
Expand All @@ -2386,7 +2386,7 @@ func (destCCIP *DestCCIPModule) AssertEventReportAccepted(
Msg("ReportAccepted event received before finalized timestamp")
totalTime = time.Second
}
receipt, err := destCCIP.Common.ChainClient.GetTxReceipt(reportAccepted.Raw.TxHash)
receipt, err := destCCIP.Common.ChainClient.GetTxReceipt(reportAccepted.LogInfo.TxHash)
if err != nil {
lggr.Warn().Msg("Failed to get receipt for ReportAccepted event")
}
Expand All @@ -2397,7 +2397,7 @@ func (destCCIP *DestCCIPModule) AssertEventReportAccepted(
reqStat.UpdateState(lggr, seqNum, testreporters.Commit, totalTime, testreporters.Success,
&testreporters.TransactionStats{
GasUsed: gasUsed,
TxHash: reportAccepted.Raw.TxHash.String(),
TxHash: reportAccepted.LogInfo.TxHash.Hex(),
CommitRoot: fmt.Sprintf("%x", reportAccepted.MerkleRoot),
})
return reportAccepted, receivedAt, nil
Expand Down Expand Up @@ -2462,7 +2462,7 @@ func (destCCIP *DestCCIPModule) AssertReportBlessed(
value, ok = destCCIP.ReportBlessedBySeqNum.Load(seqNum)
}
if ok && value != nil {
vLogs, exists := value.(*types.Log)
vLogs, exists := value.(*contracts.LogInfo)
if exists {
// if the root is found, set the value for all the sequence numbers in the interval and delete the root from the map
if foundAsRoot {
Expand Down Expand Up @@ -3337,8 +3337,11 @@ func (lane *CCIPLane) StartEventWatchers() error {
SequenceNumber: e.Message.SequenceNumber,
DataLength: len(e.Message.Data),
NoOfTokens: len(e.Message.TokenAmounts),
Raw: e.Raw,
Fee: e.Message.FeeTokenAmount,
LogInfo: contracts.LogInfo{
BlockNumber: e.Raw.BlockNumber,
TxHash: e.Raw.TxHash,
},
Fee: e.Message.FeeTokenAmount,
}))
} else {
lane.Source.CCIPSendRequestedWatcher.Store(e.Raw.TxHash.Hex(), []*contracts.SendReqEventData{
Expand All @@ -3347,8 +3350,11 @@ func (lane *CCIPLane) StartEventWatchers() error {
SequenceNumber: e.Message.SequenceNumber,
DataLength: len(e.Message.Data),
NoOfTokens: len(e.Message.TokenAmounts),
Raw: e.Raw,
Fee: e.Message.FeeTokenAmount,
LogInfo: contracts.LogInfo{
BlockNumber: e.Raw.BlockNumber,
TxHash: e.Raw.TxHash,
},
Fee: e.Message.FeeTokenAmount,
},
})
}
Expand Down Expand Up @@ -3382,7 +3388,10 @@ func (lane *CCIPLane) StartEventWatchers() error {
Min: e.Report.Interval.Min,
Max: e.Report.Interval.Max,
MerkleRoot: e.Report.MerkleRoot,
Raw: e.Raw,
LogInfo: contracts.LogInfo{
BlockNumber: e.Raw.BlockNumber,
TxHash: e.Raw.TxHash,
},
})
}
lane.Dest.ReportAcceptedWatcher = testutils.DeleteNilEntriesFromMap(lane.Dest.ReportAcceptedWatcher)
Expand Down Expand Up @@ -3411,7 +3420,10 @@ func (lane *CCIPLane) StartEventWatchers() error {
case e := <-reportBlessedEvent:
lane.Logger.Info().Msgf("TaggedRootBlessed event received for root %x", e.TaggedRoot.Root)
if e.TaggedRoot.CommitStore == lane.Dest.CommitStore.EthAddress {
lane.Dest.ReportBlessedWatcher.Store(e.TaggedRoot.Root, &e.Raw)
lane.Dest.ReportBlessedWatcher.Store(e.TaggedRoot.Root, &contracts.LogInfo{
BlockNumber: e.Raw.BlockNumber,
TxHash: e.Raw.TxHash,
})
}
lane.Dest.ReportBlessedWatcher = testutils.DeleteNilEntriesFromMap(lane.Dest.ReportBlessedWatcher)
case <-lane.Context.Done():
Expand Down Expand Up @@ -3443,7 +3455,10 @@ func (lane *CCIPLane) StartEventWatchers() error {
MessageId: e.MessageId,
State: e.State,
ReturnData: e.ReturnData,
Raw: e.Raw,
LogInfo: contracts.LogInfo{
BlockNumber: e.Raw.BlockNumber,
TxHash: e.Raw.TxHash,
},
})
lane.Dest.ExecStateChangedWatcher = testutils.DeleteNilEntriesFromMap(lane.Dest.ExecStateChangedWatcher)
case <-lane.Context.Done():
Expand Down
11 changes: 8 additions & 3 deletions integration-tests/ccip-tests/contracts/contract_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/abihelpers"
)

type LogInfo struct {
BlockNumber uint64
TxHash common.Hash
}

// Name denotes a contract name
type Name string

Expand Down Expand Up @@ -955,7 +960,7 @@ type CommitStoreReportAccepted struct {
Min uint64
Max uint64
MerkleRoot [32]byte
Raw types.Log
LogInfo LogInfo
}

type CommitStoreWrapper struct {
Expand Down Expand Up @@ -1496,7 +1501,7 @@ type SendReqEventData struct {
SequenceNumber uint64
DataLength int
NoOfTokens int
Raw types.Log
LogInfo LogInfo
Fee *big.Int
}

Expand Down Expand Up @@ -2151,7 +2156,7 @@ type EVM2EVMOffRampExecutionStateChanged struct {
MessageId [32]byte
State uint8
ReturnData []byte
Raw types.Log
LogInfo LogInfo
}

type MockAggregator struct {
Expand Down
7 changes: 3 additions & 4 deletions integration-tests/ccip-tests/load/ccip_loadgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ func (c *CCIPE2ELoad) Call(_ *wasp.Generator) *wasp.Response {
}

txConfirmationTime := time.Now().UTC()
lggr.Info().Str("tx", sendTx.Hash().Hex()).Msg("waiting for tx to be mined")
lggr = lggr.With().Str("Msg Tx", sendTx.Hash().String()).Logger()

stats.UpdateState(&lggr, 0, testreporters.TX, txConfirmationTime.Sub(startTime), testreporters.Success, nil)
Expand Down Expand Up @@ -296,13 +295,13 @@ func (c *CCIPE2ELoad) Validate(lggr zerolog.Logger, sendTx *types.Transaction, t
// if the finality tag is enabled and the last finalized block is greater than the block number of the message
// consider the message finalized
if c.Lane.Source.Common.ChainClient.GetNetworkConfig().FinalityDepth == 0 &&
lstFinalizedBlock != 0 && lstFinalizedBlock > msgLogs[0].Raw.BlockNumber {
lstFinalizedBlock != 0 && lstFinalizedBlock > msgLogs[0].LogInfo.BlockNumber {
sourceLogFinalizedAt = c.LastFinalizedTimestamp.Load()
for i, stat := range stats {
stat.UpdateState(&lggr, stat.SeqNum, testreporters.SourceLogFinalized,
sourceLogFinalizedAt.Sub(sourceLogTime), testreporters.Success,
&testreporters.TransactionStats{
TxHash: msgLogs[i].Raw.TxHash.Hex(),
TxHash: msgLogs[i].LogInfo.TxHash.Hex(),
FinalizedByBlock: strconv.FormatUint(lstFinalizedBlock, 10),
FinalizedAt: sourceLogFinalizedAt.String(),
Fee: msgLogs[i].Fee.String(),
Expand All @@ -314,7 +313,7 @@ func (c *CCIPE2ELoad) Validate(lggr zerolog.Logger, sendTx *types.Transaction, t
} else {
var finalizingBlock uint64
sourceLogFinalizedAt, finalizingBlock, err = c.Lane.Source.AssertSendRequestedLogFinalized(
&lggr, msgLogs[0].Raw.TxHash, msgLogs, sourceLogTime, stats)
&lggr, msgLogs[0].LogInfo.TxHash, msgLogs, sourceLogTime, stats)
if err != nil {
return err
}
Expand Down

0 comments on commit dfdc827

Please sign in to comment.