Skip to content

Commit

Permalink
load public params from vault when possible (#431)
Browse files Browse the repository at this point in the history
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
  • Loading branch information
adecaro authored Dec 5, 2022
1 parent f3bfb27 commit 00d73a0
Show file tree
Hide file tree
Showing 33 changed files with 401 additions and 258 deletions.
4 changes: 4 additions & 0 deletions docs/core-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ token:
network: default # the name of the network this TMS refers to (Fabric, Orion, etc)
channel: testchannel # the name of the network's channel this TMS refers to, if applicable
namespace: tns # the name of the channel's namespace this TMS refers to, if applicable
# the name of the driver that provides the implementation of the Driver API.
# This field is optional. If not specified, the Token-SDK will derive this information by fetching the public parameters
# from the remote network
driver: zkatdlog
# sections dedicated to the definition of the wallets
wallets:
# owner wallets
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/dgraph-io/ristretto v0.1.0
github.com/golang/protobuf v1.5.2
github.com/hashicorp/go-uuid v1.0.2
github.com/hyperledger-labs/fabric-smart-client v0.1.1-0.20221130141649-2080c0c69de1
github.com/hyperledger-labs/fabric-smart-client v0.1.1-0.20221201145120-5b16ba703b2f
github.com/hyperledger-labs/orion-sdk-go v0.2.5
github.com/hyperledger-labs/orion-server v0.2.5
github.com/hyperledger/fabric v1.4.0-rc1.0.20220808214918-83596078d0c3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,8 @@ github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmK
github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo=
github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
github.com/hyperledger-labs/fabric-smart-client v0.1.1-0.20221130141649-2080c0c69de1 h1:F5/QSzgJsQS0rFsO8YK2mAQ0VU8ZclQrprzt82Z0PeU=
github.com/hyperledger-labs/fabric-smart-client v0.1.1-0.20221130141649-2080c0c69de1/go.mod h1:WtNWdKVbF9R1/2hIBVQUlR9Zl3T0TdkzUcCQTc2Eqk4=
github.com/hyperledger-labs/fabric-smart-client v0.1.1-0.20221201145120-5b16ba703b2f h1:rBsPzYygDoG3fm7CdwlgsR6UhlnmeoOCERMuoSYaRNo=
github.com/hyperledger-labs/fabric-smart-client v0.1.1-0.20221201145120-5b16ba703b2f/go.mod h1:WtNWdKVbF9R1/2hIBVQUlR9Zl3T0TdkzUcCQTc2Eqk4=
github.com/hyperledger-labs/orion-sdk-go v0.2.5 h1:HFGRTuMZgzo9EtyJeFAhVSlbrj6x3jtY0aDcghdjzRE=
github.com/hyperledger-labs/orion-sdk-go v0.2.5/go.mod h1:At8hiFATfkDXQ4AFLVbaTiC9GDhVDo8aN/supb1KBb4=
github.com/hyperledger-labs/orion-server v0.2.5 h1:aFudmB9SAnsT5v8jhazkuszEu0pdJNFqaYZF2GpvAuI=
Expand Down
3 changes: 1 addition & 2 deletions integration/token/dvp/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import (
)

func TestAll(network *integration.Infrastructure) {
// Give some time for the network to start
// TODO: remove this in the future by makings sure that the FSC nodes are connected to the p2p network.
// give some time to the nodes to get the public parameters
time.Sleep(10 * time.Second)

// Ready to go
Expand Down
2 changes: 1 addition & 1 deletion integration/token/fungible/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func SwapCash(network *integration.Infrastructure, id string, wallet string, typ
func CheckPublicParams(network *integration.Infrastructure, ids ...string) {
for _, id := range ids {
_, err := network.Client(id).CallView("CheckPublicParamsMatch", common.JSONMarshall(&views.CheckPublicParamsMatch{}))
Expect(err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred(), "failed to check public params at [%s]", id)
}
}

Expand Down
3 changes: 3 additions & 0 deletions integration/token/fungible/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ var BobAcceptedTransactions = []*ttxdb.TransactionRecord{
func TestAll(network *integration.Infrastructure, auditor string) {
RegisterAuditor(network, auditor)

// give some time to the nodes to get the public parameters
time.Sleep(10 * time.Second)

CheckPublicParams(network, "issuer", auditor, "alice", "bob", "charlie", "manager")

t0 := time.Now()
Expand Down
12 changes: 12 additions & 0 deletions integration/token/interop/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
)

func TestHTLCSingleNetwork(network *integration.Infrastructure) {
// give some time to the nodes to get the public parameters
time.Sleep(10 * time.Second)

defaultTMSID := token.TMSID{}
RegisterAuditor(network)

Expand Down Expand Up @@ -165,6 +168,9 @@ func TestHTLCSingleNetwork(network *integration.Infrastructure) {
}

func TestHTLCTwoNetworks(network *integration.Infrastructure) {
// give some time to the nodes to get the public parameters
time.Sleep(10 * time.Second)

alpha := token.TMSID{Network: "alpha"}
beta := token.TMSID{Network: "beta"}

Expand Down Expand Up @@ -224,6 +230,9 @@ func TestHTLCTwoNetworks(network *integration.Infrastructure) {
}

func TestHTLCNoCrossClaimTwoNetworks(network *integration.Infrastructure) {
// give some time to the nodes to get the public parameters
time.Sleep(10 * time.Second)

alpha := token.TMSID{Network: "alpha"}
beta := token.TMSID{Network: "beta"}

Expand Down Expand Up @@ -276,6 +285,9 @@ func TestHTLCNoCrossClaimTwoNetworks(network *integration.Infrastructure) {
}

func TestFastExchange(network *integration.Infrastructure) {
// give some time to the nodes to get the public parameters
time.Sleep(10 * time.Second)

alpha := token.TMSID{Network: "alpha"}
beta := token.TMSID{Network: "beta"}

Expand Down
3 changes: 3 additions & 0 deletions integration/token/nft/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
)

func TestAll(network *integration.Infrastructure) {
// give some time to the nodes to get the public parameters
time.Sleep(10 * time.Second)

registerAuditor(network)
houseID := issueHouse(network, "alice", 4)
queryHouse(network, "alice", houseID, "5th Avenue")
Expand Down
5 changes: 2 additions & 3 deletions token/core/cmd/certfier/keypairgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import (
"os"
"path/filepath"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/hyperledger-labs/fabric-token-sdk/token/core"
_ "github.com/hyperledger-labs/fabric-token-sdk/token/services/certifier/dummy"
_ "github.com/hyperledger-labs/fabric-token-sdk/token/services/certifier/interactive"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var driver string
Expand Down
1 change: 1 addition & 0 deletions token/core/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package core

import (
Expand Down
17 changes: 11 additions & 6 deletions token/core/fabtoken/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hyperledger-labs/fabric-token-sdk/token/core"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/config"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/ppm"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/identity"
"github.com/hyperledger-labs/fabric-token-sdk/token/core/identity/msp"
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
Expand Down Expand Up @@ -89,18 +90,22 @@ func (d *Driver) NewTokenService(sp view2.ServiceProvider, publicParamsFetcher d
service := fabtoken.NewService(
sp,
tmsID,
fabtoken.NewPublicParamsManager(&fabtoken.VaultPublicParamsLoader{
PublicParamsFetcher: publicParamsFetcher,
PPLabel: fabtoken.PublicParameters,
}),
ppm.NewPublicParamsManager(
fabtoken.PublicParameters,
qe,
&fabtoken.PublicParamsLoader{
PublicParamsFetcher: publicParamsFetcher,
PPLabel: fabtoken.PublicParameters,
},
),
&fabtoken.VaultTokenLoader{TokenVault: qe},
qe,
identity.NewProvider(sp, fabtoken.NewEnrollmentIDDeserializer(), wallets),
fabtoken.NewDeserializer(),
tmsConfig,
kvs.GetService(sp),
)
if err := service.PPM.Update(); err != nil {
if err := service.PPM.Load(); err != nil {
return nil, errors.WithMessage(err, "failed to update public parameters")
}
return service, nil
Expand All @@ -119,7 +124,7 @@ func (d *Driver) NewPublicParametersManager(params driver.PublicParameters) (dri
if !ok {
return nil, errors.Errorf("invalid public parameters type [%T]", params)
}
return fabtoken.NewPublicParamsManagerFromParams(pp), nil
return ppm.NewPublicParamsManagerFromParams(pp), nil
}

func init() {
Expand Down
17 changes: 8 additions & 9 deletions token/core/fabtoken/loaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func (s *VaultTokenLoader) GetTokens(ids []*token.ID) ([]string, []*token.Token,
return s.TokenVault.GetTokens(ids...)
}

// VaultPublicParamsLoader allows one to fetch the public parameters for fabtoken
type VaultPublicParamsLoader struct {
// PublicParamsLoader allows one to fetch the public parameters for fabtoken
type PublicParamsLoader struct {
PublicParamsFetcher driver.PublicParamsFetcher
PPLabel string
}

// Fetch fetches the public parameters from the backend
func (s *VaultPublicParamsLoader) Fetch() ([]byte, error) {
func (s *PublicParamsLoader) Fetch() ([]byte, error) {
logger.Debugf("fetch public parameters...")
raw, err := s.PublicParamsFetcher.Fetch()
if err != nil {
Expand All @@ -46,7 +46,7 @@ func (s *VaultPublicParamsLoader) Fetch() ([]byte, error) {
}

// FetchParams fetches the public parameters from the backend and unmarshal them
func (s *VaultPublicParamsLoader) FetchParams() (*PublicParams, error) {
func (s *PublicParamsLoader) FetchParams() (*PublicParams, error) {
logger.Debugf("fetch public parameters...")
raw, err := s.PublicParamsFetcher.Fetch()
if err != nil {
Expand All @@ -55,14 +55,13 @@ func (s *VaultPublicParamsLoader) FetchParams() (*PublicParams, error) {
}

logger.Debugf("fetched public parameters [%s], unmarshal them...", hash.Hashable(raw).String())
pp := &PublicParams{}
pp.Label = s.PPLabel
if err := pp.Deserialize(raw); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal public parameters")
pp, err := NewPublicParamsFromBytes(raw, s.PPLabel)
if err != nil {
return nil, err
}
logger.Debugf("fetched public parameters [%s], unmarshal them...done", hash.Hashable(raw).String())
if err := pp.Validate(); err != nil {
return nil, errors.Wrap(err, "failed to validate public parameters")
}
logger.Debugf("fetched public parameters [%s], unmarshal them...done", hash.Hashable(raw).String())
return pp, nil
}
1 change: 1 addition & 0 deletions token/core/fabtoken/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package fabtoken

import "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/flogging"
Expand Down
123 changes: 0 additions & 123 deletions token/core/fabtoken/ppm.go

This file was deleted.

Loading

0 comments on commit 00d73a0

Please sign in to comment.