forked from TrueCloudLab/frostfs-contract
Revert "[#152] netmap: allow only alphabet calls in addPeer
"
This reverts commit c008910157
.
This commit is contained in:
parent
2472678b9f
commit
81c12b3f24
2 changed files with 23 additions and 43 deletions
|
@ -199,30 +199,27 @@ func AddPeer(nodeInfo []byte) {
|
|||
notaryDisabled := storage.Get(ctx, notaryDisabledKey).(bool)
|
||||
|
||||
var ( // for invocation collection without notary
|
||||
alphabet []common.IRNode
|
||||
nodeKey []byte
|
||||
alphabet []common.IRNode
|
||||
nodeKey []byte
|
||||
alphabetCall bool
|
||||
)
|
||||
|
||||
publicKey := nodeInfo[2:35] // offset:2, len:33
|
||||
|
||||
if notaryDisabled {
|
||||
alphabet = common.AlphabetNodes()
|
||||
nodeKey = common.InnerRingInvoker(alphabet)
|
||||
if len(nodeKey) == 0 {
|
||||
if !runtime.CheckWitness(publicKey) {
|
||||
panic("addPeer: witness check failed")
|
||||
}
|
||||
runtime.Notify("AddPeer", nodeInfo)
|
||||
return
|
||||
}
|
||||
alphabetCall = len(nodeKey) != 0
|
||||
} else {
|
||||
multiaddr := common.AlphabetAddress()
|
||||
alphabetCall = runtime.CheckWitness(multiaddr)
|
||||
}
|
||||
|
||||
if !alphabetCall {
|
||||
publicKey := nodeInfo[2:35] // offset:2, len:33
|
||||
if !runtime.CheckWitness(publicKey) {
|
||||
panic("addPeer: witness check failed")
|
||||
}
|
||||
if !runtime.CheckWitness(multiaddr) {
|
||||
panic("addPeer: alphabet witness check failed")
|
||||
}
|
||||
runtime.Notify("AddPeer", nodeInfo)
|
||||
return
|
||||
}
|
||||
|
||||
candidate := storageNode{
|
||||
|
|
|
@ -68,46 +68,29 @@ func TestAddPeer(t *testing.T) {
|
|||
acc := NewAccount(t, bc)
|
||||
dummyInfo := dummyNodeInfo(acc)
|
||||
|
||||
tx := PrepareInvoke(t, bc, CommitteeAcc, h, "addPeer", dummyInfo)
|
||||
acc1 := NewAccount(t, bc)
|
||||
tx := PrepareInvoke(t, bc, acc1, h, "addPeer", dummyInfo)
|
||||
AddBlock(t, bc, tx)
|
||||
CheckFault(t, bc, tx.Hash(), "addPeer: witness check failed")
|
||||
CheckFault(t, bc, tx.Hash(), "witness check failed")
|
||||
|
||||
tx = PrepareInvoke(t, bc, acc, h, "addPeer", dummyInfo)
|
||||
AddBlock(t, bc, tx)
|
||||
CheckFault(t, bc, tx.Hash(), "addPeer: alphabet witness check failed")
|
||||
|
||||
tx = PrepareInvoke(t, bc, []*wallet.Account{CommitteeAcc, acc}, h, "addPeer", dummyInfo)
|
||||
AddBlockCheckHalt(t, bc, tx)
|
||||
|
||||
tx = PrepareInvoke(t, bc, acc, h, "netmapCandidates")
|
||||
AddBlock(t, bc, tx)
|
||||
|
||||
checkNode := func(t *testing.T, info []byte, state int64, actual stackitem.Item) {
|
||||
// Actual is netmap.netmapNode.
|
||||
require.Equal(t, stackitem.NewStruct([]stackitem.Item{
|
||||
stackitem.NewStruct([]stackitem.Item{
|
||||
stackitem.NewByteArray(dummyInfo),
|
||||
}),
|
||||
stackitem.NewBigInteger(big.NewInt(state)),
|
||||
}), actual)
|
||||
}
|
||||
|
||||
aer := CheckHalt(t, bc, tx.Hash())
|
||||
nodes, _ := aer.Stack[0].Value().([]stackitem.Item)
|
||||
require.Equal(t, 1, len(nodes))
|
||||
checkNode(t, dummyInfo, 1, nodes[0])
|
||||
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, []*wallet.Account{CommitteeAcc, acc}, h, "addPeer", dummyInfo)
|
||||
AddBlockCheckHalt(t, bc, tx)
|
||||
|
||||
tx = PrepareInvoke(t, bc, acc, h, "netmapCandidates")
|
||||
tx = PrepareInvoke(t, bc, acc, h, "addPeer", dummyInfo)
|
||||
AddBlock(t, bc, tx)
|
||||
|
||||
aer = CheckHalt(t, bc, tx.Hash())
|
||||
nodes, _ = aer.Stack[0].Value().([]stackitem.Item)
|
||||
require.Equal(t, 1, len(nodes))
|
||||
checkNode(t, dummyInfo, 1, nodes[0])
|
||||
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)
|
||||
}
|
||||
|
||||
func TestUpdateState(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue