Skip to content

Conversation

@adecaro
Copy link
Contributor

@adecaro adecaro commented Aug 26, 2025

The goal of this PR is to allow the binding of multiple identities at the same time so to same in the number of DB connections when binding multiple identities. This will be used in the token-sdk.

This PR is linked to FTS's PR hyperledger-labs/fabric-token-sdk#1245

@HayimShaul HayimShaul force-pushed the 1009-unite-multiple-binds-2 branch from 312e46b to 5625f77 Compare September 3, 2025 14:04
Copy link
Member

@mbrandenburger mbrandenburger left a comment

Choose a reason for hiding this comment

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

Thanks again for addressing my comments.

@HayimShaul HayimShaul force-pushed the 1009-unite-multiple-binds-2 branch from 674d885 to 2cd3a22 Compare September 8, 2025 06:57
@AkramBitar AkramBitar self-requested a review September 8, 2025 11:49
@HayimShaul HayimShaul force-pushed the 1009-unite-multiple-binds-2 branch from 585de5d to 406634f Compare October 29, 2025 16:30
Copy link
Member

@mbrandenburger mbrandenburger left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! It is in a good shape already. See below a few minor comments to address. Thanks again!

Comment on lines 17 to 19
sss := sdk.WithBool("fabric.enabled", true)
err := sdk.DryRunWiring(NewFrom, sss)
assert.NoError(t, err)
Copy link
Member

Choose a reason for hiding this comment

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

Is this change really needed?

logger.DebugfContext(ctx, "Id [%s] is an unregistered long term ID", longTerm.UniqueID())

func (db *BindingStore) PutBindings(ctx context.Context, longTerm view.Identity, ephemerals ...view.Identity) error {
if len(ephemerals) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

should we also check that longTerm is not nil?

Comment on lines +33 to +57
// Input identities
longTerm := view.Identity("long")
e1 := view.Identity("eph1")
e2 := view.Identity("eph2")

// Check that store does not have bindings for e1 and e2
lt, err := db.GetLongTerm(ctx, e1)
require.NoError(t, err)
require.ElementsMatch(t, len(lt), 0)
lt, err = db.GetLongTerm(ctx, e2)
require.NoError(t, err)
require.ElementsMatch(t, len(lt), 0)

// Create new bindings
err = db.PutBindings(ctx, longTerm, e1, e2)
require.NoError(t, err)

// Check that the bindings where correctly written
lt, err = db.GetLongTerm(ctx, e1)
require.NoError(t, err)
require.ElementsMatch(t, lt, longTerm)

lt, err = db.GetLongTerm(ctx, e2)
require.NoError(t, err)
require.ElementsMatch(t, lt, longTerm)
Copy link
Member

Choose a reason for hiding this comment

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

The test looks more or less identical to the postgres/binding_test.go

Let's move the actual test case to common/binding_test.go into a test method e.g.,
RunPutBindingTests, which takes as input a database abstraction.

In this file here we just instantiate the db and call common.RunPutBindingTests(t, db). We do the same for the postgres test.

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

With the latest changes you moved the actual binding code to common. Please consider doing the same for the actual test cases.

// Build single INSERT with multiple VALUES
query := fmt.Sprintf(`INSERT INTO %s (ephemeral_hash, long_term_id) VALUES `, db.table)

args := []interface{}{}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
args := []interface{}{}
var args := []any

Copy link
Contributor

Choose a reason for hiding this comment

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

platform/view/services/storage/driver/sql/common/binding.go:116:13: []any (type) is not an expression

Copy link
Member

Choose a reason for hiding this comment

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

sorry - this was a sloppy suggestion. it should be var args []any.

Comment on lines +97 to +99
if len(ephemerals) > 1000 {
return errors.Errorf("Too many ephemerals (%d). Max allowed is 1000", len(ephemerals))
}
Copy link
Member

Choose a reason for hiding this comment

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

Please update the go docs for this function to clearly describe that here is a limit.

Comment on lines -16 to -18
func TestWiring(t *testing.T) {
assert.NoError(t, sdk.DryRunWiring(NewFrom, sdk.WithBool("fabric.enabled", true)))
}
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I did not mean to remove this test. I meant to just revert the changes to it. Let's keep it. It's a good test.

Comment on lines +33 to +57
// Input identities
longTerm := view.Identity("long")
e1 := view.Identity("eph1")
e2 := view.Identity("eph2")

// Check that store does not have bindings for e1 and e2
lt, err := db.GetLongTerm(ctx, e1)
require.NoError(t, err)
require.ElementsMatch(t, len(lt), 0)
lt, err = db.GetLongTerm(ctx, e2)
require.NoError(t, err)
require.ElementsMatch(t, len(lt), 0)

// Create new bindings
err = db.PutBindings(ctx, longTerm, e1, e2)
require.NoError(t, err)

// Check that the bindings where correctly written
lt, err = db.GetLongTerm(ctx, e1)
require.NoError(t, err)
require.ElementsMatch(t, lt, longTerm)

lt, err = db.GetLongTerm(ctx, e2)
require.NoError(t, err)
require.ElementsMatch(t, lt, longTerm)
Copy link
Member

Choose a reason for hiding this comment

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

With the latest changes you moved the actual binding code to common. Please consider doing the same for the actual test cases.

"github.com/stretchr/testify/require"
)

func TestPutBindingsMultipleEphemeralsPostgres(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

What about adding one case to test our limit :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

endpoint.Service: Bind multiple ephemeral identities at the same time

4 participants