Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reindexing token pool created events when creation and active are different steps #1599

Closed
wants to merge 8 commits into from
5 changes: 5 additions & 0 deletions internal/definitions/handler_tokenpool.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.

Check failure on line 1 in internal/definitions/handler_tokenpool.go

View workflow job for this annotation

GitHub Actions / build

Expected:2024, Actual: 2023 Kaleido, Inc. (goheader)
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -92,6 +92,11 @@
}
}

if existing.ID.Equals(pool.ID) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to understand how we got to this point with a duplicate ID. Your description indicates we are processing a TokenPoolCreated event, so we're coming in via eventManager.TokenPoolCreated() and then definitionSender.DefineTokenPool() and then here.

But in eventManager.TokenPoolCreated(), there is a check for an existing pool. Is that check failing to find the existing pool and allowing it to get down to here?

Copy link
Contributor

@awrichar awrichar Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also worth confirming... were you running the latest release (v1.3.2) when you saw this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, running the latest v1.3.2 release

log.L(ctx).Warnf("Received duplicate token pool creation with ID=%s, ignoring and carrying on for token connector: %s", pool.ID, pool.Connector)
break
}

// Any other conflict - reject
return HandlerResult{Action: core.ActionReject, CustomCorrelator: correlator}, i18n.NewError(ctx, coremsgs.MsgDefRejectedConflict, "token pool", pool.ID, existing.ID)
}
Expand Down
12 changes: 12 additions & 0 deletions internal/events/token_pool_created.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,24 @@ func (em *eventManager) loadFromOperation(ctx context.Context, pool *tokens.Toke
return nil, nil
}

activateOp, _ := em.txHelper.FindOperationInTransaction(ctx, pool.TX.ID, core.OpTypeTokenActivatePool)
if activateOp != nil {
log.L(ctx).Debugf("There was a separate operation to active the pool for tx=%s status=%s", pool.TX.ID, core.OpTypeTokenActivatePool)
}

stagedPool, err = txcommon.RetrieveTokenPoolCreateInputs(ctx, op)
if err != nil || stagedPool.ID == nil || stagedPool.Namespace == "" || stagedPool.Name == "" {
log.L(ctx).Errorf("Error loading pool info for transaction '%s' (%s) - ignoring: %v", pool.TX.ID, err, op.Input)
return nil, nil
}

// If we have successfully activated the pool
// Then set the pool published to true
// As it won't be in the initial payload
if activateOp != nil && activateOp.Status == core.OpStatusSucceeded {
stagedPool.Published = true
}

awrichar marked this conversation as resolved.
Show resolved Hide resolved
if err = addPoolDetailsFromPlugin(stagedPool, pool); err != nil {
log.L(ctx).Errorf("Error processing pool for transaction '%s' (%s) - ignoring", pool.TX.ID, err)
return nil, nil
Expand Down
Loading