forked from TrueCloudLab/frostfs-contract
[#146] netmap: allow to update peer info
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
7fe7188e7d
commit
a72392f672
3 changed files with 64 additions and 6 deletions
|
@ -191,6 +191,7 @@ func UpdateInnerRing(keys []interop.PublicKey) {
|
||||||
// by Alphabet node. If it was invoked by node candidate, it produces AddPeer
|
// by Alphabet node. If it was invoked by node candidate, it produces AddPeer
|
||||||
// notification. Otherwise method throws panic.
|
// notification. Otherwise method throws panic.
|
||||||
//
|
//
|
||||||
|
// If the candidate already exists, it's info is updated.
|
||||||
// NodeInfo argument contains stable marshaled version of netmap.NodeInfo
|
// NodeInfo argument contains stable marshaled version of netmap.NodeInfo
|
||||||
// structure.
|
// structure.
|
||||||
func AddPeer(nodeInfo []byte) {
|
func AddPeer(nodeInfo []byte) {
|
||||||
|
@ -519,11 +520,6 @@ func addToNetmap(ctx storage.Context, n storageNode) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
data := storage.Get(ctx, storageKey)
|
|
||||||
if data != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
storage.Put(ctx, storageKey, std.Serialize(node))
|
storage.Put(ctx, storageKey, std.Serialize(node))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
@ -138,13 +139,14 @@ func DeployContract(t *testing.T, bc *core.Blockchain, path string, data interfa
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckHalt checks that transaction persisted with HALT state.
|
// CheckHalt checks that transaction persisted with HALT state.
|
||||||
func CheckHalt(t *testing.T, bc *core.Blockchain, h util.Uint256, stack ...stackitem.Item) {
|
func CheckHalt(t *testing.T, bc *core.Blockchain, h util.Uint256, stack ...stackitem.Item) *state.AppExecResult {
|
||||||
aer, err := bc.GetAppExecResults(h, trigger.Application)
|
aer, err := bc.GetAppExecResults(h, trigger.Application)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, vm.HaltState, aer[0].VMState, aer[0].FaultException)
|
require.Equal(t, vm.HaltState, aer[0].VMState, aer[0].FaultException)
|
||||||
if len(stack) != 0 {
|
if len(stack) != 0 {
|
||||||
require.Equal(t, stack, aer[0].Stack)
|
require.Equal(t, stack, aer[0].Stack)
|
||||||
}
|
}
|
||||||
|
return &aer[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckFault checks that transaction persisted with FAULT state.
|
// CheckFault checks that transaction persisted with FAULT state.
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||||
"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/wallet"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
const netmapPath = "../netmap"
|
const netmapPath = "../netmap"
|
||||||
|
@ -18,3 +22,59 @@ func deployNetmapContract(t *testing.T, bc *core.Blockchain, addrBalance, addrCo
|
||||||
args[4] = append([]interface{}{}, config...)
|
args[4] = append([]interface{}{}, config...)
|
||||||
return DeployContract(t, bc, netmapPath, args)
|
return DeployContract(t, bc, netmapPath, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func prepareNetmapContract(t *testing.T, bc *core.Blockchain) util.Uint160 {
|
||||||
|
addrNNS := DeployContract(t, bc, nnsPath, nil)
|
||||||
|
|
||||||
|
ctrNetmap, err := ContractInfo(CommitteeAcc.Contract.ScriptHash(), netmapPath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
ctrBalance, err := ContractInfo(CommitteeAcc.Contract.ScriptHash(), balancePath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
ctrContainer, err := ContractInfo(CommitteeAcc.Contract.ScriptHash(), containerPath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
deployContainerContract(t, bc, ctrNetmap.Hash, ctrBalance.Hash, addrNNS)
|
||||||
|
deployBalanceContract(t, bc, ctrNetmap.Hash, ctrContainer.Hash)
|
||||||
|
return deployNetmapContract(t, bc, ctrBalance.Hash, ctrContainer.Hash, "ContainerFee", []byte{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func dummyNodeInfo(acc *wallet.Account) []byte {
|
||||||
|
ni := make([]byte, 66)
|
||||||
|
rand.Read(ni)
|
||||||
|
copy(ni[2:], acc.PrivateKey().PublicKey().Bytes())
|
||||||
|
return ni
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddPeer(t *testing.T) {
|
||||||
|
bc := NewChain(t)
|
||||||
|
h := prepareNetmapContract(t, bc)
|
||||||
|
|
||||||
|
acc := NewAccount(t, bc)
|
||||||
|
dummyInfo := dummyNodeInfo(acc)
|
||||||
|
|
||||||
|
acc1 := NewAccount(t, bc)
|
||||||
|
tx := PrepareInvoke(t, bc, acc1, h, "addPeer", dummyInfo)
|
||||||
|
AddBlock(t, bc, tx)
|
||||||
|
CheckFault(t, bc, tx.Hash(), "witness check failed")
|
||||||
|
|
||||||
|
tx = PrepareInvoke(t, bc, acc, h, "addPeer", dummyInfo)
|
||||||
|
AddBlock(t, bc, tx)
|
||||||
|
|
||||||
|
aer := CheckHalt(t, bc, tx.Hash())
|
||||||
|
require.Equal(t, 1, len(aer.Events))
|
||||||
|
require.Equal(t, "AddPeer", aer.Events[0].Name)
|
||||||
|
require.Equal(t, stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray(dummyInfo)}),
|
||||||
|
aer.Events[0].Item)
|
||||||
|
|
||||||
|
dummyInfo[0] ^= 0xFF
|
||||||
|
tx = PrepareInvoke(t, bc, acc, h, "addPeer", dummyInfo)
|
||||||
|
AddBlock(t, bc, tx)
|
||||||
|
|
||||||
|
aer = CheckHalt(t, bc, tx.Hash())
|
||||||
|
require.Equal(t, 1, len(aer.Events))
|
||||||
|
require.Equal(t, "AddPeer", aer.Events[0].Name)
|
||||||
|
require.Equal(t, stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray(dummyInfo)}),
|
||||||
|
aer.Events[0].Item)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue