Remove method alphabetAddress from frostfs contract #77

Merged
fyrchik merged 1 commit from acid-ant/frostfs-contract:feature/17-rm-alphabet-addr into master 2024-03-05 11:15:08 +00:00
5 changed files with 26 additions and 66 deletions

View file

@ -1,6 +1,5 @@
name: "FrostFS" name: "FrostFS"
safemethods: safemethods:
- "alphabetAddress"
- "config" - "config"
- "innerRingCandidates" - "innerRingCandidates"
- "listConfig" - "listConfig"

View file

@ -9,7 +9,6 @@ import (
"github.com/nspcc-dev/neo-go/pkg/interop/native/ledger" "github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
"github.com/nspcc-dev/neo-go/pkg/interop/native/management" "github.com/nspcc-dev/neo-go/pkg/interop/native/management"
"github.com/nspcc-dev/neo-go/pkg/interop/native/roles" "github.com/nspcc-dev/neo-go/pkg/interop/native/roles"
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage" "github.com/nspcc-dev/neo-go/pkg/interop/storage"
) )
@ -26,7 +25,6 @@ const (
CandidateFeeConfigKey = "InnerRingCandidateFee" CandidateFeeConfigKey = "InnerRingCandidateFee"
withdrawFeeConfigKey = "WithdrawFee" withdrawFeeConfigKey = "WithdrawFee"
alphabetKey = "alphabet"
candidatesKey = "candidates" candidatesKey = "candidates"
processingContractKey = "processingScriptHash" processingContractKey = "processingScriptHash"
@ -71,9 +69,6 @@ func _deploy(data any, isUpdate bool) {
} }
} }
// initialize all storage slices
common.SetSerialized(ctx, alphabetKey, args.keys)
storage.Put(ctx, processingContractKey, args.addrProc) storage.Put(ctx, processingContractKey, args.addrProc)
ln := len(args.config) ln := len(args.config)
@ -106,13 +101,6 @@ func Update(script []byte, manifest []byte, data any) {
runtime.Log("frostfs contract updated") runtime.Log("frostfs contract updated")
} }
// AlphabetAddress returns 2\3n+1 multisignature address of alphabet nodes.
// It is used in sidechain notary disabled environment.
func AlphabetAddress() interop.Hash160 {
ctx := storage.GetReadOnlyContext()
return multiaddress(getAlphabetNodes(ctx))
}
// InnerRingCandidates returns an array of structures that contain an Inner Ring // InnerRingCandidates returns an array of structures that contain an Inner Ring
// candidate node key. // candidate node key.
func InnerRingCandidates() []common.IRNode { func InnerRingCandidates() []common.IRNode {
@ -137,8 +125,7 @@ func InnerRingCandidateRemove(key interop.PublicKey) {
keyOwner := runtime.CheckWitness(key) keyOwner := runtime.CheckWitness(key)
if !keyOwner { if !keyOwner {
multiaddr := AlphabetAddress() if !runtime.CheckWitness(common.AlphabetAddress()) {
if !runtime.CheckWitness(multiaddr) {
panic("this method must be invoked by candidate or alphabet") panic("this method must be invoked by candidate or alphabet")
} }
} }
@ -358,16 +345,6 @@ func Version() int {
return common.Version return common.Version
} }
// getAlphabetNodes returns a deserialized slice of nodes from storage.
func getAlphabetNodes(ctx storage.Context) []interop.PublicKey {
data := storage.Get(ctx, alphabetKey)
if data != nil {
return std.Deserialize(data.([]byte)).([]interop.PublicKey)
}
return []interop.PublicKey{}
}
// getConfig returns the installed frostfs configuration value or nil if it is not set. // getConfig returns the installed frostfs configuration value or nil if it is not set.
func getConfig(ctx storage.Context, key any) interface{} { func getConfig(ctx storage.Context, key any) interface{} {
postfix := key.([]byte) postfix := key.([]byte)

View file

@ -3,19 +3,11 @@ package processing
import ( import (
"git.frostfs.info/TrueCloudLab/frostfs-contract/common" "git.frostfs.info/TrueCloudLab/frostfs-contract/common"
"github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
"github.com/nspcc-dev/neo-go/pkg/interop/native/gas" "github.com/nspcc-dev/neo-go/pkg/interop/native/gas"
"github.com/nspcc-dev/neo-go/pkg/interop/native/ledger" "github.com/nspcc-dev/neo-go/pkg/interop/native/ledger"
"github.com/nspcc-dev/neo-go/pkg/interop/native/management" "github.com/nspcc-dev/neo-go/pkg/interop/native/management"
"github.com/nspcc-dev/neo-go/pkg/interop/native/roles" "github.com/nspcc-dev/neo-go/pkg/interop/native/roles"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
)
const (
frostfsContractKey = "frostfsScriptHash"
multiaddrMethod = "alphabetAddress"
) )
// OnNEP17Payment is a callback for NEP-17 compatible native GAS contract. // OnNEP17Payment is a callback for NEP-17 compatible native GAS contract.
@ -33,18 +25,6 @@ func _deploy(data any, isUpdate bool) {
return return
} }
args := data.(struct {
addrFrostFS interop.Hash160
})
ctx := storage.GetContext()
if len(args.addrFrostFS) != interop.Hash160Len {
panic("incorrect length of contract script hash")
}
storage.Put(ctx, frostfsContractKey, args.addrFrostFS)
runtime.Log("processing contract initialized") runtime.Log("processing contract initialized")
} }
@ -66,11 +46,7 @@ func Update(script []byte, manifest []byte, data any) {
// Verify method returns true if transaction contains valid multisignature of // Verify method returns true if transaction contains valid multisignature of
// Alphabet nodes of the Inner Ring. // Alphabet nodes of the Inner Ring.
func Verify() bool { func Verify() bool {
ctx := storage.GetContext() return runtime.CheckWitness(common.AlphabetAddress())
frostfsContractAddr := storage.Get(ctx, frostfsContractKey).(interop.Hash160)
multiaddr := contract.Call(frostfsContractAddr, multiaddrMethod, contract.ReadOnly).(interop.Hash160)
return runtime.CheckWitness(multiaddr)
} }
// Version returns the version of the contract. // Version returns the version of the contract.

View file

@ -103,11 +103,6 @@ func New(actor Actor, hash util.Uint160) *Contract {
return &Contract{ContractReader{actor, hash}, actor, hash} return &Contract{ContractReader{actor, hash}, actor, hash}
} }
// AlphabetAddress invokes `alphabetAddress` method of contract.
func (c *ContractReader) AlphabetAddress() (util.Uint160, error) {
return unwrap.Uint160(c.invoker.Call(c.hash, "alphabetAddress"))
}
// Config invokes `config` method of contract. // Config invokes `config` method of contract.
func (c *ContractReader) Config(key []byte) (any, error) { func (c *ContractReader) Config(key []byte) (any, error) {
return func(item stackitem.Item, err error) (any, error) { return func(item stackitem.Item, err error) (any, error) {

View file

@ -4,28 +4,41 @@ import (
"path" "path"
"testing" "testing"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/neotest" "github.com/nspcc-dev/neo-go/pkg/neotest"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/stretchr/testify/require"
) )
const processingPath = "../processing" const processingPath = "../processing"
func deployProcessingContract(t *testing.T, e *neotest.Executor, addrFrostFS util.Uint160) util.Uint160 { func deployProcessingContract(t *testing.T, e *neotest.Executor) util.Uint160 {
c := neotest.CompileFile(t, e.CommitteeHash, processingPath, path.Join(processingPath, "config.yml")) c := neotest.CompileFile(t, e.CommitteeHash, processingPath, path.Join(processingPath, "config.yml"))
args := make([]any, 1) e.DeployContract(t, c, nil)
args[0] = addrFrostFS
e.DeployContract(t, c, args)
return c.Hash return c.Hash
} }
func newProcessingInvoker(t *testing.T) (*neotest.ContractInvoker, neotest.Signer) { func newProcessingInvoker(t *testing.T) (*neotest.ContractInvoker, neotest.SingleSigner) {
frostfsInvoker, irMultiAcc, _ := newFrostFSInvoker(t, 2) e := newExecutor(t)
hash := deployProcessingContract(t, frostfsInvoker.Executor, frostfsInvoker.Hash)
return frostfsInvoker.CommitteeInvoker(hash), irMultiAcc acc, err := wallet.NewAccount()
require.NoError(t, err)
sig := neotest.NewSingleSigner(acc)
gasHash, err := e.Chain.GetNativeContractScriptHash(nativenames.Gas)
require.NoError(t, err)
vc := e.CommitteeInvoker(gasHash).WithSigners(e.Validator)
vc.Invoke(t, true, "transfer",
e.Validator.ScriptHash(), sig.ScriptHash(),
int64(10_0000_0000), nil)
hash := deployProcessingContract(t, e)
return e.CommitteeInvoker(hash), sig
} }
func TestVerify_Processing(t *testing.T) { func TestVerify_Processing(t *testing.T) {
@ -35,6 +48,6 @@ func TestVerify_Processing(t *testing.T) {
cIR := c.WithSigners(irMultiAcc) cIR := c.WithSigners(irMultiAcc)
cIR.Invoke(t, stackitem.NewBool(true), method) cIR.Invoke(t, stackitem.NewBool(false), method)
c.Invoke(t, stackitem.NewBool(false), method) c.Invoke(t, stackitem.NewBool(true), method)
} }