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

Enable non-multiparty namespaces #878

Merged
merged 27 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
999cc61
Split definition methods out of Broadcast Manager into new Definition…
awrichar May 3, 2022
0312f18
Rename "Broadcast" methods of Definition Sender to "Create"
awrichar May 11, 2022
96dde60
Move BatchState struct into core
awrichar May 12, 2022
8c3a404
Conditionally initialize multiparty messaging managers
awrichar Jun 23, 2022
58d11f8
Add more config deprecation warnings
awrichar Jun 23, 2022
35d21d5
Store definitions locally in gateway mode
awrichar May 12, 2022
cd7c354
Use lowercase for nested array keys due to Viper bug
awrichar Jun 23, 2022
e974ce4
Add helper for disabling routes based on orchestrator features
awrichar Jun 24, 2022
37a5864
Add some additional test coverage
awrichar Jun 24, 2022
09d4255
Disable identity resolution for local definitions
awrichar Jun 24, 2022
3ee0967
Allow plugin config to be omitted
awrichar Jun 24, 2022
4fe64b6
Remove default value for "ffdx"
awrichar Jun 27, 2022
82a0476
Move FFI/API creation methods into Definition Sender
awrichar Jun 27, 2022
dced5c5
Combine defsender into definitions package
awrichar Jun 28, 2022
a8e080e
Shorten definition handler filenames
awrichar Jun 28, 2022
5fbce07
Handle gateway-mode token pool definitions directly
awrichar Jun 28, 2022
cc3b5f3
Handle gateway-mode contract definitions directly
awrichar Jun 28, 2022
0f22e53
Disable datatype definitions in gateway mode
awrichar Jun 28, 2022
5779bc4
Remove unused CreateDefinition method from public interface
awrichar Jun 28, 2022
3f77c04
Handle gateway-mode identity definitions directly
awrichar Jun 28, 2022
1f60a54
Move plugin start calls to namespace manager
awrichar Jun 28, 2022
2a02fee
Complete test coverage and remove dead branches
awrichar Jun 28, 2022
007f8a8
Combine init of definition sender/handler
awrichar Jun 28, 2022
03989eb
Fix up identity update path
awrichar Jun 28, 2022
fb5c9a3
Remove references to "gateway mode"
awrichar Jun 28, 2022
0ce79ca
Return an error if key cannot be resolved in non-multiparty mode
awrichar Jun 29, 2022
784a4db
Allow FFIs and APIs to be created without a message ID
awrichar Jun 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ $(eval $(call makemock, internal/broadcast, Manager, broadcast
$(eval $(call makemock, internal/privatemessaging, Manager, privatemessagingmocks))
$(eval $(call makemock, internal/shareddownload, Manager, shareddownloadmocks))
$(eval $(call makemock, internal/shareddownload, Callbacks, shareddownloadmocks))
$(eval $(call makemock, internal/definitions, DefinitionHandler, definitionsmocks))
$(eval $(call makemock, internal/definitions, Handler, definitionsmocks))
$(eval $(call makemock, internal/definitions, Sender, definitionsmocks))
$(eval $(call makemock, internal/events, EventManager, eventmocks))
$(eval $(call makemock, internal/namespace, Manager, namespacemocks))
$(eval $(call makemock, internal/networkmap, Manager, networkmapmocks))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- No down migration (can't add back NOT NULL constraint)
16 changes: 16 additions & 0 deletions db/migrations/postgres/000094_allow_local_definitions.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BEGIN;
ALTER TABLE identities RENAME COLUMN messages_claim TO messages_claim_old;
ALTER TABLE identities ADD COLUMN messages_claim UUID;
UPDATE identities SET messages_claim = messages_claim_old;
ALTER TABLE identities DROP COLUMN messages_claim_old;

ALTER TABLE ffi RENAME COLUMN message_id TO message_id_old;
ALTER TABLE ffi ADD COLUMN message_id UUID;
UPDATE ffi SET message_id = message_id_old;
ALTER TABLE ffi DROP COLUMN message_id_old;

ALTER TABLE contractapis RENAME COLUMN message_id TO message_id_old;
ALTER TABLE contractapis ADD COLUMN message_id UUID;
UPDATE contractapis SET message_id = message_id_old;
ALTER TABLE contractapis DROP COLUMN message_id_old;
COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- No down migration (can't add back NOT NULL constraint)
14 changes: 14 additions & 0 deletions db/migrations/sqlite/000094_allow_local_definitions.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALTER TABLE identities RENAME COLUMN messages_claim TO messages_claim_old;
ALTER TABLE identities ADD COLUMN messages_claim UUID;
UPDATE identities SET messages_claim = messages_claim_old;
ALTER TABLE identities DROP COLUMN messages_claim_old;

ALTER TABLE ffi RENAME COLUMN message_id TO message_id_old;
ALTER TABLE ffi ADD COLUMN message_id UUID;
UPDATE ffi SET message_id = message_id_old;
ALTER TABLE ffi DROP COLUMN message_id_old;

ALTER TABLE contractapis RENAME COLUMN message_id TO message_id_old;
ALTER TABLE contractapis ADD COLUMN message_id UUID;
UPDATE contractapis SET message_id = message_id_old;
ALTER TABLE contractapis DROP COLUMN message_id_old;
6 changes: 3 additions & 3 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ nav_order: 2

|Key|Description|Type|Default Value|
|---|-----------|----|-------------|
|type|The Data Exchange plugin to use|`string`|`ffdx`
|type|The Data Exchange plugin to use|`string`|`<nil>`

## dataexchange.ffdx

Expand Down Expand Up @@ -585,11 +585,11 @@ nav_order: 2

|Key|Description|Type|Default Value|
|---|-----------|----|-------------|
|defaultKey|A default signing key for blockchain transactions within this namespace|`string`|`<nil>`
|defaultkey|A default signing key for blockchain transactions within this namespace|`string`|`<nil>`
|description|A description for the namespace|`string`|`<nil>`
|name|The name of the namespace (must be unique)|`string`|`<nil>`
|plugins|The list of plugins for this namespace|`string`|`<nil>`
|remoteName|The namespace name to be sent in plugin calls, if it differs from namespace name|`string`|`<nil>`
|remotename|The namespace name to be sent in plugin calls, if it differs from namespace name|`string`|`<nil>`

## namespaces.predefined[].multiparty

Expand Down
4 changes: 4 additions & 0 deletions internal/apiserver/route_get_data_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/ffapi"
"github.com/hyperledger/firefly/internal/coremsgs"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/pkg/core"
"github.com/hyperledger/firefly/pkg/database"
)
Expand All @@ -40,6 +41,9 @@ var getDataBlob = &ffapi.Route{
JSONOutputCodes: []int{http.StatusOK},
Extensions: &coreExtensions{
FilterFactory: database.MessageQueryFactory,
EnabledIf: func(or orchestrator.Orchestrator) bool {
return or.MultiParty() != nil
},
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
blob, reader, err := cr.or.Data().DownloadBlob(cr.ctx, r.PP["dataid"])
if err == nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/apiserver/route_get_data_blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/fftypes"
"github.com/hyperledger/firefly/mocks/datamocks"
"github.com/hyperledger/firefly/mocks/multipartymocks"
"github.com/hyperledger/firefly/pkg/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -33,6 +34,7 @@ func TestGetDataBlob(t *testing.T) {
o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("Data").Return(mdm)
o.On("MultiParty").Return(&multipartymocks.Manager{})
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/data/abcd1234/blob", nil)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()
Expand Down
7 changes: 5 additions & 2 deletions internal/apiserver/route_get_group_by_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/ffapi"
"github.com/hyperledger/firefly/internal/coremsgs"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/pkg/core"
)

Expand All @@ -37,9 +38,11 @@ var getGroupByHash = &ffapi.Route{
JSONOutputValue: func() interface{} { return &core.Group{} },
JSONOutputCodes: []int{http.StatusOK},
Extensions: &coreExtensions{
EnabledIf: func(or orchestrator.Orchestrator) bool {
return or.PrivateMessaging() != nil
},
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
output, err = cr.or.PrivateMessaging().GetGroupByID(cr.ctx, r.PP["hash"])
return output, err
return cr.or.PrivateMessaging().GetGroupByID(cr.ctx, r.PP["hash"])
},
},
}
4 changes: 4 additions & 0 deletions internal/apiserver/route_get_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/ffapi"
"github.com/hyperledger/firefly/internal/coremsgs"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/pkg/core"
"github.com/hyperledger/firefly/pkg/database"
)
Expand All @@ -37,6 +38,9 @@ var getGroups = &ffapi.Route{
JSONOutputCodes: []int{http.StatusOK},
Extensions: &coreExtensions{
FilterFactory: database.GroupQueryFactory,
EnabledIf: func(or orchestrator.Orchestrator) bool {
return or.PrivateMessaging() != nil
},
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
return filterResult(cr.or.PrivateMessaging().GetGroups(cr.ctx, cr.filter))
},
Expand Down
7 changes: 5 additions & 2 deletions internal/apiserver/route_get_status_batchmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/hyperledger/firefly-common/pkg/ffapi"
"github.com/hyperledger/firefly/internal/batch"
"github.com/hyperledger/firefly/internal/coremsgs"
"github.com/hyperledger/firefly/internal/orchestrator"
)

var getStatusBatchManager = &ffapi.Route{
Expand All @@ -35,9 +36,11 @@ var getStatusBatchManager = &ffapi.Route{
JSONOutputValue: func() interface{} { return &batch.ManagerStatus{} },
JSONOutputCodes: []int{http.StatusOK},
Extensions: &coreExtensions{
EnabledIf: func(or orchestrator.Orchestrator) bool {
return or.BatchManager() != nil
},
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
output = cr.or.BatchManager().Status()
return output, nil
return cr.or.BatchManager().Status(), nil
},
},
}
4 changes: 4 additions & 0 deletions internal/apiserver/route_post_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/hyperledger/firefly-common/pkg/ffapi"
"github.com/hyperledger/firefly-common/pkg/fftypes"
"github.com/hyperledger/firefly/internal/coremsgs"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/pkg/core"
)

Expand All @@ -46,6 +47,9 @@ var postData = &ffapi.Route{
JSONOutputValue: func() interface{} { return &core.Data{} },
JSONOutputCodes: []int{http.StatusCreated},
Extensions: &coreExtensions{
EnabledIf: func(or orchestrator.Orchestrator) bool {
return or.MultiParty() != nil
},
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
output, err = cr.or.Data().UploadJSON(cr.ctx, r.Input.(*core.DataRefOrValue))
return output, err
Expand Down
9 changes: 9 additions & 0 deletions internal/apiserver/route_post_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/log"
"github.com/hyperledger/firefly/mocks/datamocks"
"github.com/hyperledger/firefly/mocks/multipartymocks"
"github.com/hyperledger/firefly/pkg/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -34,6 +35,7 @@ import (
func TestPostDataJSON(t *testing.T) {
o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)
input := core.Data{}
var buf bytes.Buffer
Expand All @@ -52,6 +54,7 @@ func TestPostDataJSON(t *testing.T) {
func TestPostDataJSONDefaultNS(t *testing.T) {
o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)
input := core.Data{}
var buf bytes.Buffer
Expand All @@ -72,6 +75,7 @@ func TestPostDataBinary(t *testing.T) {

o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)

var b bytes.Buffer
Expand All @@ -97,6 +101,7 @@ func TestPostDataBinaryObjAutoMeta(t *testing.T) {

o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)

var b bytes.Buffer
Expand Down Expand Up @@ -143,6 +148,7 @@ func TestPostDataBinaryStringMetadata(t *testing.T) {

o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)

var b bytes.Buffer
Expand Down Expand Up @@ -176,6 +182,7 @@ func TestPostDataTrailingMetadata(t *testing.T) {

o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)

var b bytes.Buffer
Expand Down Expand Up @@ -207,6 +214,7 @@ func TestPostDataBinaryMissing(t *testing.T) {

o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)

var b bytes.Buffer
Expand All @@ -231,6 +239,7 @@ func TestPostDataBadForm(t *testing.T) {

o, r := newTestAPIServer()
mdm := &datamocks.Manager{}
o.On("MultiParty").Return(&multipartymocks.Manager{})
o.On("Data").Return(mdm)

var b bytes.Buffer
Expand Down
4 changes: 4 additions & 0 deletions internal/apiserver/route_post_network_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/ffapi"
"github.com/hyperledger/firefly/internal/coremsgs"
"github.com/hyperledger/firefly/internal/orchestrator"
"github.com/hyperledger/firefly/pkg/core"
)

Expand All @@ -35,6 +36,9 @@ var postNetworkAction = &ffapi.Route{
JSONOutputValue: func() interface{} { return &core.NetworkAction{} },
JSONOutputCodes: []int{http.StatusAccepted},
Extensions: &coreExtensions{
EnabledIf: func(or orchestrator.Orchestrator) bool {
return or.MultiParty() != nil
},
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
err = cr.or.SubmitNetworkAction(cr.ctx, r.Input.(*core.NetworkAction))
return r.Input, err
Expand Down
2 changes: 2 additions & 0 deletions internal/apiserver/route_post_network_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (
"net/http/httptest"
"testing"

"github.com/hyperledger/firefly/mocks/multipartymocks"
"github.com/hyperledger/firefly/pkg/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestPostNetworkAction(t *testing.T) {
o, r := newTestAPIServer()
o.On("MultiParty").Return(&multipartymocks.Manager{})
input := core.NetworkAction{}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
Expand Down
4 changes: 3 additions & 1 deletion internal/apiserver/route_post_new_contract_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ var postNewContractAPI = &ffapi.Route{
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
r.SuccessStatus = syncRetcode(waitConfirm)
return cr.or.Contracts().BroadcastContractAPI(cr.ctx, cr.apiBaseURL, r.Input.(*core.ContractAPI), waitConfirm)
api := r.Input.(*core.ContractAPI)
err = cr.or.DefinitionSender().DefineContractAPI(cr.ctx, cr.apiBaseURL, api, waitConfirm)
return api, err
},
},
}
16 changes: 7 additions & 9 deletions internal/apiserver/route_post_new_contract_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,41 @@ import (
"net/http/httptest"
"testing"

"github.com/hyperledger/firefly/mocks/contractmocks"
"github.com/hyperledger/firefly/mocks/definitionsmocks"
"github.com/hyperledger/firefly/pkg/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestPostNewContractAPI(t *testing.T) {
o, r := newTestAPIServer()
mcm := &contractmocks.Manager{}
o.On("Contracts").Return(mcm)
mds := &definitionsmocks.Sender{}
o.On("DefinitionSender").Return(mds)
input := core.Datatype{}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/apis", &buf)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), false).
Return(&core.ContractAPI{}, nil)
mds.On("DefineContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), false).Return(nil)
r.ServeHTTP(res, req)

assert.Equal(t, 202, res.Result().StatusCode)
}

func TestPostNewContractAPISync(t *testing.T) {
o, r := newTestAPIServer()
mcm := &contractmocks.Manager{}
o.On("Contracts").Return(mcm)
mds := &definitionsmocks.Sender{}
o.On("DefinitionSender").Return(mds)
input := core.Datatype{}
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(&input)
req := httptest.NewRequest("POST", "/api/v1/namespaces/ns1/apis?confirm", &buf)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), true).
Return(&core.ContractAPI{}, nil)
mds.On("DefineContractAPI", mock.Anything, mock.Anything, mock.AnythingOfType("*core.ContractAPI"), true).Return(nil)
r.ServeHTTP(res, req)

assert.Equal(t, 200, res.Result().StatusCode)
Expand Down
4 changes: 3 additions & 1 deletion internal/apiserver/route_post_new_contract_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ var postNewContractInterface = &ffapi.Route{
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
r.SuccessStatus = syncRetcode(waitConfirm)
return cr.or.Contracts().BroadcastFFI(cr.ctx, r.Input.(*core.FFI), waitConfirm)
ffi := r.Input.(*core.FFI)
err = cr.or.DefinitionSender().DefineFFI(cr.ctx, ffi, waitConfirm)
return ffi, err
},
},
}
Loading