[#152] netmap: allow only alphabet calls in addPeer
If notary is enabled only alphabet calls are expected. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
a72392f672
commit
c008910157
2 changed files with 44 additions and 23 deletions
|
@ -201,26 +201,29 @@ func AddPeer(nodeInfo []byte) {
|
||||||
var ( // for invocation collection without notary
|
var ( // for invocation collection without notary
|
||||||
alphabet []common.IRNode
|
alphabet []common.IRNode
|
||||||
nodeKey []byte
|
nodeKey []byte
|
||||||
alphabetCall bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
publicKey := nodeInfo[2:35] // offset:2, len:33
|
||||||
|
|
||||||
if notaryDisabled {
|
if notaryDisabled {
|
||||||
alphabet = common.AlphabetNodes()
|
alphabet = common.AlphabetNodes()
|
||||||
nodeKey = common.InnerRingInvoker(alphabet)
|
nodeKey = common.InnerRingInvoker(alphabet)
|
||||||
alphabetCall = len(nodeKey) != 0
|
if 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) {
|
if !runtime.CheckWitness(publicKey) {
|
||||||
panic("addPeer: witness check failed")
|
panic("addPeer: witness check failed")
|
||||||
}
|
}
|
||||||
runtime.Notify("AddPeer", nodeInfo)
|
runtime.Notify("AddPeer", nodeInfo)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
multiaddr := common.AlphabetAddress()
|
||||||
|
if !runtime.CheckWitness(publicKey) {
|
||||||
|
panic("addPeer: witness check failed")
|
||||||
|
}
|
||||||
|
if !runtime.CheckWitness(multiaddr) {
|
||||||
|
panic("addPeer: alphabet witness check failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
candidate := storageNode{
|
candidate := storageNode{
|
||||||
info: nodeInfo,
|
info: nodeInfo,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -54,27 +55,44 @@ func TestAddPeer(t *testing.T) {
|
||||||
acc := NewAccount(t, bc)
|
acc := NewAccount(t, bc)
|
||||||
dummyInfo := dummyNodeInfo(acc)
|
dummyInfo := dummyNodeInfo(acc)
|
||||||
|
|
||||||
acc1 := NewAccount(t, bc)
|
tx := PrepareInvoke(t, bc, CommitteeAcc, h, "addPeer", dummyInfo)
|
||||||
tx := PrepareInvoke(t, bc, acc1, h, "addPeer", dummyInfo)
|
|
||||||
AddBlock(t, bc, tx)
|
AddBlock(t, bc, tx)
|
||||||
CheckFault(t, bc, tx.Hash(), "witness check failed")
|
CheckFault(t, bc, tx.Hash(), "addPeer: witness check failed")
|
||||||
|
|
||||||
tx = PrepareInvoke(t, bc, acc, h, "addPeer", dummyInfo)
|
tx = PrepareInvoke(t, bc, acc, h, "addPeer", dummyInfo)
|
||||||
AddBlock(t, bc, tx)
|
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())
|
aer := CheckHalt(t, bc, tx.Hash())
|
||||||
require.Equal(t, 1, len(aer.Events))
|
nodes, _ := aer.Stack[0].Value().([]stackitem.Item)
|
||||||
require.Equal(t, "AddPeer", aer.Events[0].Name)
|
require.Equal(t, 1, len(nodes))
|
||||||
require.Equal(t, stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray(dummyInfo)}),
|
checkNode(t, dummyInfo, 1, nodes[0])
|
||||||
aer.Events[0].Item)
|
|
||||||
|
|
||||||
dummyInfo[0] ^= 0xFF
|
dummyInfo[0] ^= 0xFF
|
||||||
tx = PrepareInvoke(t, bc, acc, h, "addPeer", dummyInfo)
|
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)
|
AddBlock(t, bc, tx)
|
||||||
|
|
||||||
aer = CheckHalt(t, bc, tx.Hash())
|
aer = CheckHalt(t, bc, tx.Hash())
|
||||||
require.Equal(t, 1, len(aer.Events))
|
nodes, _ = aer.Stack[0].Value().([]stackitem.Item)
|
||||||
require.Equal(t, "AddPeer", aer.Events[0].Name)
|
require.Equal(t, 1, len(nodes))
|
||||||
require.Equal(t, stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray(dummyInfo)}),
|
checkNode(t, dummyInfo, 1, nodes[0])
|
||||||
aer.Events[0].Item)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue