@@ -13,6 +13,7 @@ import (
1313 "github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
1414 "github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
1515 "github.com/nspcc-dev/neo-go/pkg/rpcclient/notary"
16+ "github.com/nspcc-dev/neo-go/pkg/smartcontract"
1617 "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
1718 "github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
1819 "github.com/nspcc-dev/neo-go/pkg/util"
@@ -25,6 +26,12 @@ const (
2526 methodUpdate = "update"
2627)
2728
29+ const (
30+ _ uint8 = iota
31+ witnessAlphabet
32+ witnessAlphabetAndCommittee
33+ )
34+
2835// syncNeoFSContractPrm groups parameters of syncNeoFSContract.
2936type syncNeoFSContractPrm struct {
3037 logger * zap.Logger
@@ -56,10 +63,12 @@ type syncNeoFSContractPrm struct {
5663 // if set, syncNeoFSContract attempts to deploy the contract when it's
5764 // missing on the chain
5865 tryDeploy bool
59- // is contract must be deployed by the committee
60- committeeDeployRequired bool
61- // additional allowed contracts to be added to the NNS one if committeeDeployRequired
62- extraCommitteeDeployAllowedContracts []util.Uint160
66+ // 0: committee witness is not needed
67+ // witnessAlphabet: committee 2/3n+1 with allowed alphabetDeployAllowedContracts
68+ // witnessAlphabetAndCommittee: witnessAlphabet + committee n/2+1 with allowed NNS contract calls
69+ deployWitness uint8
70+ // contracts that are allowed to be called for the Alphabet-witnessed deployment
71+ alphabetDeployAllowedContracts []util.Uint160
6372
6473 // optional constructor of extra arguments to be passed into method deploying
6574 // the contract. If returns both nil, no data is passed (noExtraDeployArgs can
@@ -126,11 +135,46 @@ func syncNeoFSContract(ctx context.Context, prm syncNeoFSContractPrm) (util.Uint
126135 Sender () util.Uint160
127136 }
128137 var managementContract * management.Contract
129- if prm .committeeDeployRequired {
130- deployCommitteeActor , err := newCommitteeNotaryActorWithCustomCommitteeSigner (prm .blockchain , prm .localAcc , prm .committee , func (s * transaction.Signer ) {
131- s .Scopes = transaction .CustomContracts
132- s .AllowedContracts = append (prm .extraCommitteeDeployAllowedContracts , prm .nnsContract )
133- })
138+ if prm .deployWitness > 0 {
139+ if prm .deployWitness != witnessAlphabet && prm .deployWitness != witnessAlphabetAndCommittee {
140+ panic (fmt .Sprintf ("unexpected deploy witness mode value %v" , prm .deployWitness ))
141+ }
142+
143+ committeeDefaultMultiSigAcc := wallet .NewAccountFromPrivateKey (prm .localAcc .PrivateKey ())
144+ err := committeeDefaultMultiSigAcc .ConvertMultisig (smartcontract .GetDefaultHonestNodeCount (len (prm .committee )), prm .committee )
145+ if err != nil {
146+ return util.Uint160 {}, fmt .Errorf ("compose committee default multi-signature account: %w" , err )
147+ }
148+
149+ signers := make ([]actor.SignerAccount , 2 , 3 )
150+ // payer
151+ signers [0 ].Account = prm .localAcc
152+ signers [0 ].Signer .Account = prm .localAcc .ScriptHash ()
153+ signers [0 ].Signer .Scopes = transaction .None
154+ // Alphabet
155+ signers [1 ].Account = committeeDefaultMultiSigAcc
156+ signers [1 ].Signer .Account = committeeDefaultMultiSigAcc .ScriptHash ()
157+ signers [1 ].Signer .Scopes = transaction .CustomContracts
158+ signers [1 ].Signer .AllowedContracts = prm .alphabetDeployAllowedContracts
159+
160+ if prm .deployWitness == witnessAlphabetAndCommittee {
161+ committeeMajorityMultiSigAcc := wallet .NewAccountFromPrivateKey (prm .localAcc .PrivateKey ())
162+ err := committeeMajorityMultiSigAcc .ConvertMultisig (smartcontract .GetMajorityHonestNodeCount (len (prm .committee )), prm .committee )
163+ if err != nil {
164+ return util.Uint160 {}, fmt .Errorf ("compose committee majority multi-signature account: %w" , err )
165+ }
166+
167+ signers = append (signers , actor.SignerAccount {
168+ Signer : transaction.Signer {
169+ Account : committeeMajorityMultiSigAcc .ScriptHash (),
170+ Scopes : transaction .CustomContracts ,
171+ AllowedContracts : []util.Uint160 {prm .nnsContract },
172+ },
173+ Account : committeeMajorityMultiSigAcc ,
174+ })
175+ }
176+
177+ deployCommitteeActor , err := notary .NewActor (prm .blockchain , signers , prm .localAcc )
134178 if err != nil {
135179 return util.Uint160 {}, fmt .Errorf ("create Notary service client sending deploy transactions to be signed by the committee: %w" , err )
136180 }
@@ -226,7 +270,7 @@ func syncNeoFSContract(ctx context.Context, prm syncNeoFSContractPrm) (util.Uint
226270 nefCp := prm .localNEF
227271 manifestCp := prm .localManifest
228272
229- if prm .committeeDeployRequired {
273+ if prm .deployWitness > 0 {
230274 l .Info ("contract requires committee witness for deployment, sending Notary request..." )
231275
232276 mainTxID , fallbackTxID , vub , err := prm .committeeLocalActor .Notarize (managementContract .DeployTransaction (& nefCp , & manifestCp , extraDeployArgs ))
0 commit comments