forked from TrueCloudLab/frostfs-contract
[#154] netmap: allow only alphabet calls in updateState
This reverts commit a9503b5c
This commit is contained in:
parent
8553320e1c
commit
68eac87e64
2 changed files with 49 additions and 18 deletions
|
@ -259,31 +259,21 @@ func UpdateState(state int, publicKey interop.PublicKey) {
|
||||||
notaryDisabled := storage.Get(ctx, notaryDisabledKey).(bool)
|
notaryDisabled := storage.Get(ctx, notaryDisabledKey).(bool)
|
||||||
|
|
||||||
var ( // for invocation collection without notary
|
var ( // for invocation collection without notary
|
||||||
alphabet []common.IRNode
|
alphabet []common.IRNode
|
||||||
nodeKey []byte
|
nodeKey []byte
|
||||||
alphabetCall bool
|
|
||||||
)
|
)
|
||||||
|
|
||||||
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 {
|
if !runtime.CheckWitness(publicKey) {
|
||||||
multiaddr := common.AlphabetAddress()
|
panic("updateState: witness check failed")
|
||||||
alphabetCall = runtime.CheckWitness(multiaddr)
|
}
|
||||||
}
|
runtime.Notify("UpdateState", state, publicKey)
|
||||||
|
return
|
||||||
if !alphabetCall {
|
|
||||||
if !runtime.CheckWitness(publicKey) {
|
|
||||||
panic("updateState: witness check failed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.Notify("UpdateState", state, publicKey)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if notaryDisabled {
|
|
||||||
threshold := len(alphabet)*2/3 + 1
|
threshold := len(alphabet)*2/3 + 1
|
||||||
id := common.InvokeID([]interface{}{state, publicKey}, []byte("update"))
|
id := common.InvokeID([]interface{}{state, publicKey}, []byte("update"))
|
||||||
|
|
||||||
|
@ -293,6 +283,14 @@ func UpdateState(state int, publicKey interop.PublicKey) {
|
||||||
}
|
}
|
||||||
|
|
||||||
common.RemoveVotes(ctx, id)
|
common.RemoveVotes(ctx, id)
|
||||||
|
} else {
|
||||||
|
multiaddr := common.AlphabetAddress()
|
||||||
|
if !runtime.CheckWitness(publicKey) {
|
||||||
|
panic("updateState: witness check failed")
|
||||||
|
}
|
||||||
|
if !runtime.CheckWitness(multiaddr) {
|
||||||
|
panic("updateState: alphabet witness check failed")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch nodeState(state) {
|
switch nodeState(state) {
|
||||||
|
|
|
@ -90,3 +90,36 @@ func TestAddPeer(t *testing.T) {
|
||||||
require.Equal(t, stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray(dummyInfo)}),
|
require.Equal(t, stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray(dummyInfo)}),
|
||||||
aer.Events[0].Item)
|
aer.Events[0].Item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUpdateState(t *testing.T) {
|
||||||
|
bc := NewChain(t)
|
||||||
|
h := prepareNetmapContract(t, bc)
|
||||||
|
|
||||||
|
acc := NewAccount(t, bc)
|
||||||
|
dummyInfo := dummyNodeInfo(acc)
|
||||||
|
|
||||||
|
tx := PrepareInvoke(t, bc, []*wallet.Account{CommitteeAcc, acc}, h, "addPeer", dummyInfo)
|
||||||
|
AddBlockCheckHalt(t, bc, tx)
|
||||||
|
|
||||||
|
t.Run("missing witness", func(t *testing.T) {
|
||||||
|
tx = PrepareInvoke(t, bc, acc, h, "updateState", int64(2), acc.PrivateKey().PublicKey().Bytes())
|
||||||
|
AddBlock(t, bc, tx)
|
||||||
|
CheckFault(t, bc, tx.Hash(), "updateState: alphabet witness check failed")
|
||||||
|
|
||||||
|
tx = PrepareInvoke(t, bc, CommitteeAcc, h, "updateState", int64(2), acc.PrivateKey().PublicKey().Bytes())
|
||||||
|
AddBlock(t, bc, tx)
|
||||||
|
CheckFault(t, bc, tx.Hash(), "updateState: witness check failed")
|
||||||
|
})
|
||||||
|
|
||||||
|
tx = PrepareInvoke(t, bc, []*wallet.Account{CommitteeAcc, acc}, h,
|
||||||
|
"updateState", int64(2), acc.PrivateKey().PublicKey().Bytes())
|
||||||
|
AddBlockCheckHalt(t, bc, tx)
|
||||||
|
|
||||||
|
tx = PrepareInvoke(t, bc, acc, h, "netmapCandidates")
|
||||||
|
AddBlock(t, bc, tx)
|
||||||
|
|
||||||
|
aer := CheckHalt(t, bc, tx.Hash())
|
||||||
|
nodes, ok := aer.Stack[0].Value().([]stackitem.Item)
|
||||||
|
require.True(t, ok)
|
||||||
|
require.Equal(t, 0, len(nodes))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue