Skip to content

Commit 8637cb6

Browse files
committed
Add logs
1 parent 1e6acb6 commit 8637cb6

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

agents/agents/executor/executor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ func (e Executor) Stop(chainID uint32) {
309309
//
310310
//nolint:cyclop
311311
func (e Executor) Execute(parentCtx context.Context, message types.Message) (_ bool, err error) {
312+
fmt.Printf("entering msg execution: %v\n", message)
312313
originDomain := message.OriginDomain()
313314
destinationDomain := message.DestinationDomain()
314315

@@ -402,6 +403,7 @@ func (e Executor) Execute(parentCtx context.Context, message types.Message) (_ b
402403
}
403404

404405
_, err = e.txSubmitter.SubmitTransaction(ctx, big.NewInt(int64(destinationDomain)), func(transactor *bind.TransactOpts) (tx *ethTypes.Transaction, err error) {
406+
fmt.Printf("executing message with destination %d: %v\n", destinationDomain, message)
405407
tx, err = e.chainExecutors[message.DestinationDomain()].boundDestination.Execute(
406408
transactor,
407409
message,
@@ -793,6 +795,7 @@ func (e Executor) executeExecutable(parentCtx context.Context, chainID uint32) (
793795

794796
page := 1
795797
currentTime := uint64(e.NowFunc().Unix())
798+
fmt.Printf("got current time: %v, real time: %v\n", currentTime, time.Now().Unix())
796799

797800
messageMask := db.DBMessage{
798801
ChainID: &chainID,
@@ -807,13 +810,15 @@ func (e Executor) executeExecutable(parentCtx context.Context, chainID uint32) (
807810
if len(messages) == 0 {
808811
break
809812
}
813+
fmt.Printf("got executable messages: %v\n", messages)
810814

811815
ctx, span := e.handler.Tracer().Start(parentCtx, "executeExecutable", trace.WithAttributes(
812816
attribute.Int(metrics.ChainID, int(chainID)),
813817
attribute.Int("num_messages", len(messages)),
814818
attribute.Int(metrics.Page, page),
815819
))
816820

821+
fmt.Printf("executor processing messages: %v\n", messages)
817822
for _, message := range messages {
818823
messageExecuted, err := e.checkIfExecuted(ctx, message)
819824
if err != nil {

agents/agents/executor/executor_utils.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ func (e Executor) processMessage(ctx context.Context, message types.Message, log
154154

155155
// processAttestation processes and stores an attestation.
156156
func (e Executor) processSnapshot(ctx context.Context, snapshot types.Snapshot, logBlockNumber uint64) error {
157+
fmt.Printf("processSnapshot at block %d: %v\n", logBlockNumber, snapshot)
158+
fmt.Printf("snapshot states: %v\n", snapshot.States())
157159
for _, state := range snapshot.States() {
158160
statePayload, err := state.Encode()
159161
if err != nil {
@@ -167,9 +169,24 @@ func (e Executor) processSnapshot(ctx context.Context, snapshot types.Snapshot,
167169
if err != nil {
168170
return fmt.Errorf("could not check validity of state: %w", err)
169171
}
172+
173+
originState, err := e.chainExecutors[state.Origin()].boundOrigin.SuggestLatestState(ctx)
174+
if err != nil {
175+
return err
176+
}
177+
stateHash, err := originState.Hash()
178+
if err != nil {
179+
return err
180+
}
181+
fmt.Printf("suggested latest origin state with root: %v, hash: %v, nonce: %v\n", originState.Root(), common.BytesToHash(stateHash[:]), originState.Nonce())
182+
stateRoot := state.Root()
183+
fmt.Printf("provided snapshot. Origin: %d. SnapshotRoot: %s, Nonce: %d\n", state.Origin(), common.BytesToHash(stateRoot[:]).String(), state.Nonce())
184+
170185
if !valid {
171186
stateRoot := state.Root()
187+
fmt.Printf("snapshot has invalid state. Origin: %d. SnapshotRoot: %s, Nonce: %d\n", state.Origin(), common.BytesToHash(stateRoot[:]).String(), state.Nonce())
172188
logger.Infof("snapshot has invalid state. Origin: %d. SnapshotRoot: %s", state.Origin(), common.BytesToHash(stateRoot[:]).String())
189+
173190
return nil
174191
}
175192
}
@@ -178,6 +195,7 @@ func (e Executor) processSnapshot(ctx context.Context, snapshot types.Snapshot,
178195
return fmt.Errorf("could not get snapshot root and proofs: %w", err)
179196
}
180197

198+
fmt.Println("storing states")
181199
err = e.executorDB.StoreStates(ctx, snapshot.States(), snapshotRoot, proofs, logBlockNumber)
182200
if err != nil {
183201
return fmt.Errorf("could not store states: %w", err)

agents/agents/guard/fraud.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ func (g Guard) handleStatusUpdated(ctx context.Context, log ethTypes.Log, chainI
535535
if err != nil {
536536
return fmt.Errorf("could not parse status updated: %w", err)
537537
}
538+
fmt.Printf("handleStatusUpdated: %v on %d\n", types.AgentFlagType(statusUpdated.Flag).String(), chainID)
538539

539540
//nolint:exhaustive
540541
switch types.AgentFlagType(statusUpdated.Flag) {
@@ -708,6 +709,7 @@ func (g Guard) updateAgentStatus(ctx context.Context, chainID uint32) error {
708709
if len(eligibleAgentTrees) == 0 {
709710
return nil
710711
}
712+
fmt.Printf("got eligible agent trees: %v\n", eligibleAgentTrees)
711713

712714
var localRoot [32]byte
713715
contractCall := func(ctx context.Context) error {
@@ -727,6 +729,7 @@ func (g Guard) updateAgentStatus(ctx context.Context, chainID uint32) error {
727729
if err != nil {
728730
return fmt.Errorf("could not get block number for local root: %w", err)
729731
}
732+
fmt.Printf("got localRootBlockNumber %d for agent root %s on chain %d\n", localRootBlockNumber, common.BytesToHash(localRoot[:]).String(), chainID)
730733

731734
// Filter the eligible agent roots by the given block number and call updateAgentStatus().
732735
for _, t := range eligibleAgentTrees {
@@ -737,6 +740,7 @@ func (g Guard) updateAgentStatus(ctx context.Context, chainID uint32) error {
737740
return fmt.Errorf("could not get block number for local root: %w", err)
738741
}
739742
//nolint:nestif
743+
fmt.Printf("comparing localRootBlockNumber %d with treeBlockNumber %d\n", localRootBlockNumber, treeBlockNumber)
740744
if localRootBlockNumber >= treeBlockNumber {
741745
logger.Infof("Relaying agent status for agent %s on chain %d", tree.AgentAddress.String(), chainID)
742746
// Fetch the agent status to be relayed from Summit.

agents/agents/guard/fraud_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,25 @@ func (g GuardSuite) TestUpdateAgentStatusOnRemote() {
940940
originState, err := types.DecodeState(originStateRaw)
941941
g.Nil(err)
942942
snapshot := types.NewSnapshot([]types.State{originState})
943+
stateHash, err := originState.Hash()
944+
g.Nil(err)
945+
fmt.Printf("[TEST] submitting suggested latest origin state with root: %v, hash: %v, nonce: %v\n", originState.Root(), common.BytesToHash(stateHash[:]), originState.Nonce())
946+
947+
go func() {
948+
for {
949+
originStateRaw, err := g.OriginContract.SuggestLatestState(&bind.CallOpts{Context: g.GetTestContext()})
950+
if err != nil {
951+
continue
952+
}
953+
g.Nil(err)
954+
originState, err := types.DecodeState(originStateRaw)
955+
g.Nil(err)
956+
stateHash, err := originState.Hash()
957+
g.Nil(err)
958+
fmt.Printf("[TEST] suggested latest origin state with root: %v, hash: %v, nonce: %v\n", originState.Root(), common.BytesToHash(stateHash[:]), originState.Nonce())
959+
time.Sleep(250 * time.Millisecond)
960+
}
961+
}()
943962

944963
// Submit snapshot with Guard.
945964
guardSnapshotSignature, encodedSnapshot, _, err = snapshot.SignSnapshot(g.GetTestContext(), g.GuardBondedSigner)
@@ -1004,6 +1023,7 @@ func (g GuardSuite) TestUpdateAgentStatusOnRemote() {
10041023
g.bumpBackends()
10051024
return false
10061025
})
1026+
fmt.Println("slashed on summit")
10071027

10081028
// Get the origin state so we can submit it on the Summit.
10091029
originStateRaw, err = g.OriginContract.SuggestLatestState(&bind.CallOpts{Context: g.GetTestContext()})
@@ -1078,14 +1098,27 @@ func (g GuardSuite) TestUpdateAgentStatusOnRemote() {
10781098
NotNil(g.T(), tx)
10791099
g.TestBackendDestination.WaitForConfirmation(g.GetTestContext(), tx)
10801100

1101+
logAgentRoots := func() {
1102+
summitAgentRoot, err := g.SummitDomainClient.BondingManager().GetAgentRoot(g.GetTestContext())
1103+
g.Nil(err)
1104+
destAgentRoot, err := g.LightManagerOnDestination.AgentRoot(&bind.CallOpts{Context: g.GetTestContext()})
1105+
g.Nil(err)
1106+
nextAgentRoot, err := g.DestinationContract.NextAgentRoot(&bind.CallOpts{Context: g.GetTestContext()})
1107+
g.Nil(err)
1108+
fmt.Printf("Summit agent root: %v\n, destination agent root: %v\n, next agent root: %v\n", summitAgentRoot, destAgentRoot, nextAgentRoot)
1109+
}
10811110
// Advance time on destination and call passAgentRoot() so that the latest agent root is accepted.
10821111
increaseEvmTime(g.TestBackendDestination, optimisticPeriodSeconds+30)
10831112
g.bumpBackends()
1113+
fmt.Println("roots before passing agent root:")
1114+
logAgentRoots()
10841115
txContextDestination := g.TestBackendDestination.GetTxContext(g.GetTestContext(), g.DestinationContractMetadata.OwnerPtr())
10851116
tx, err = g.DestinationDomainClient.Destination().PassAgentRoot(txContextDestination.TransactOpts)
10861117
g.Nil(err)
10871118
g.TestBackendDestination.WaitForConfirmation(g.GetTestContext(), tx)
10881119
g.bumpBackends()
1120+
fmt.Println("roots after passing agent root:")
1121+
logAgentRoots()
10891122

10901123
// Verify that the guard eventually marks the accused agent as Slashed.
10911124
g.Eventually(func() bool {

0 commit comments

Comments
 (0)