Skip to content

Commit

Permalink
netmap: drop conditional witness behavior
Browse files Browse the repository at this point in the history
This code was based on conceptual misunderstanding of the Notary system and
never worked correctly. It makes zero sense doing nothing without an Alphabet
signature and practically we always have it, so the change won't be noticeable.

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Nov 19, 2024
1 parent d2d6e38 commit 36adb10
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
17 changes: 7 additions & 10 deletions contracts/netmap/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,12 @@ func AddPeer(nodeInfo []byte) {
publicKey := nodeInfo[nodeKeyOffset:nodeKeyEndOffset]

common.CheckWitness(publicKey)
common.CheckAlphabetWitness(common.AlphabetAddress())

if runtime.CheckWitness(common.AlphabetAddress()) {
addToNetmap(ctx, publicKey, Node{
BLOB: nodeInfo,
State: nodestate.Online,
})
}
addToNetmap(ctx, publicKey, Node{
BLOB: nodeInfo,
State: nodestate.Online,
})
}

// AddNode adds a new node into the candidate list for the next epoch. Node
Expand Down Expand Up @@ -374,11 +373,9 @@ func UpdateState(state nodestate.Type, publicKey interop.PublicKey) {
ctx := storage.GetContext()

common.CheckWitness(publicKey)
common.CheckAlphabetWitness(common.AlphabetAddress())

// TODO: see same place in AddPeer
if runtime.CheckWitness(common.AlphabetAddress()) {
updateCandidateState(ctx, publicKey, state)
}
updateCandidateState(ctx, publicKey, state)
}

// UpdateStateIR is called by the NeoFS Alphabet instead of UpdateState when
Expand Down
Binary file modified contracts/netmap/contract.nef
Binary file not shown.
2 changes: 1 addition & 1 deletion contracts/netmap/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"NeoFS Netmap","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":93,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"addNode","offset":1834,"parameters":[{"name":"n","type":"Array"}],"returntype":"Void","safe":false},{"name":"addPeer","offset":1779,"parameters":[{"name":"nodeInfo","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"addPeerIR","offset":1734,"parameters":[{"name":"nodeInfo","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"config","offset":3578,"parameters":[{"name":"key","type":"ByteArray"}],"returntype":"Any","safe":true},{"name":"deleteNode","offset":1961,"parameters":[{"name":"pkey","type":"PublicKey"}],"returntype":"Void","safe":false},{"name":"epoch","offset":2634,"parameters":[],"returntype":"Integer","safe":true},{"name":"innerRingList","offset":1689,"parameters":[],"returntype":"Array","safe":true},{"name":"lastEpochBlock","offset":2673,"parameters":[],"returntype":"Integer","safe":false},{"name":"listCandidates","offset":2862,"parameters":[],"returntype":"InteropInterface","safe":true},{"name":"listConfig","offset":3664,"parameters":[],"returntype":"Array","safe":true},{"name":"listNodes","offset":2810,"parameters":[],"returntype":"InteropInterface","safe":true},{"name":"listNodes","offset":2818,"parameters":[{"name":"epoch","type":"Integer"}],"returntype":"InteropInterface","safe":true},{"name":"netmap","offset":2712,"parameters":[],"returntype":"Array","safe":true},{"name":"netmapCandidates","offset":2794,"parameters":[],"returntype":"Array","safe":true},{"name":"newEpoch","offset":2317,"parameters":[{"name":"epochNum","type":"Integer"}],"returntype":"Void","safe":false},{"name":"setConfig","offset":3596,"parameters":[{"name":"id","type":"ByteArray"},{"name":"key","type":"ByteArray"},{"name":"val","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"snapshot","offset":2892,"parameters":[{"name":"diff","type":"Integer"}],"returntype":"Array","safe":true},{"name":"snapshotByEpoch","offset":3530,"parameters":[{"name":"epoch","type":"Integer"}],"returntype":"Array","safe":true},{"name":"subscribeForNewEpoch","offset":3720,"parameters":[{"name":"contract","type":"Hash160"}],"returntype":"Void","safe":false},{"name":"update","offset":1559,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"updateSnapshotCount","offset":3046,"parameters":[{"name":"count","type":"Integer"}],"returntype":"Void","safe":false},{"name":"updateState","offset":2212,"parameters":[{"name":"state","type":"Integer"},{"name":"publicKey","type":"PublicKey"}],"returntype":"Void","safe":false},{"name":"updateStateIR","offset":2288,"parameters":[{"name":"state","type":"Integer"},{"name":"publicKey","type":"PublicKey"}],"returntype":"Void","safe":false},{"name":"version","offset":4106,"parameters":[],"returntype":"Integer","safe":true}],"events":[{"name":"AddNode","parameters":[{"name":"publicKey","type":"PublicKey"},{"name":"addresses","type":"Array"},{"name":"attributes","type":"Map"}]},{"name":"AddPeerSuccess","parameters":[{"name":"publicKey","type":"PublicKey"}]},{"name":"UpdateStateSuccess","parameters":[{"name":"publicKey","type":"PublicKey"},{"name":"state","type":"Integer"}]},{"name":"NewEpoch","parameters":[{"name":"epoch","type":"Integer"}]},{"name":"NewEpochSubscription","parameters":[{"name":"contract","type":"Hash160"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":["update","newEpoch"]}],"supportedstandards":[],"trusts":[],"extra":null}
{"name":"NeoFS Netmap","abi":{"methods":[{"name":"_initialize","offset":0,"parameters":[],"returntype":"Void","safe":false},{"name":"_deploy","offset":93,"parameters":[{"name":"data","type":"Any"},{"name":"isUpdate","type":"Boolean"}],"returntype":"Void","safe":false},{"name":"addNode","offset":1830,"parameters":[{"name":"n","type":"Array"}],"returntype":"Void","safe":false},{"name":"addPeer","offset":1779,"parameters":[{"name":"nodeInfo","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"addPeerIR","offset":1734,"parameters":[{"name":"nodeInfo","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"config","offset":3570,"parameters":[{"name":"key","type":"ByteArray"}],"returntype":"Any","safe":true},{"name":"deleteNode","offset":1957,"parameters":[{"name":"pkey","type":"PublicKey"}],"returntype":"Void","safe":false},{"name":"epoch","offset":2626,"parameters":[],"returntype":"Integer","safe":true},{"name":"innerRingList","offset":1689,"parameters":[],"returntype":"Array","safe":true},{"name":"lastEpochBlock","offset":2665,"parameters":[],"returntype":"Integer","safe":false},{"name":"listCandidates","offset":2854,"parameters":[],"returntype":"InteropInterface","safe":true},{"name":"listConfig","offset":3656,"parameters":[],"returntype":"Array","safe":true},{"name":"listNodes","offset":2802,"parameters":[],"returntype":"InteropInterface","safe":true},{"name":"listNodes","offset":2810,"parameters":[{"name":"epoch","type":"Integer"}],"returntype":"InteropInterface","safe":true},{"name":"netmap","offset":2704,"parameters":[],"returntype":"Array","safe":true},{"name":"netmapCandidates","offset":2786,"parameters":[],"returntype":"Array","safe":true},{"name":"newEpoch","offset":2309,"parameters":[{"name":"epochNum","type":"Integer"}],"returntype":"Void","safe":false},{"name":"setConfig","offset":3588,"parameters":[{"name":"id","type":"ByteArray"},{"name":"key","type":"ByteArray"},{"name":"val","type":"ByteArray"}],"returntype":"Void","safe":false},{"name":"snapshot","offset":2884,"parameters":[{"name":"diff","type":"Integer"}],"returntype":"Array","safe":true},{"name":"snapshotByEpoch","offset":3522,"parameters":[{"name":"epoch","type":"Integer"}],"returntype":"Array","safe":true},{"name":"subscribeForNewEpoch","offset":3712,"parameters":[{"name":"contract","type":"Hash160"}],"returntype":"Void","safe":false},{"name":"update","offset":1559,"parameters":[{"name":"script","type":"ByteArray"},{"name":"manifest","type":"ByteArray"},{"name":"data","type":"Any"}],"returntype":"Void","safe":false},{"name":"updateSnapshotCount","offset":3038,"parameters":[{"name":"count","type":"Integer"}],"returntype":"Void","safe":false},{"name":"updateState","offset":2208,"parameters":[{"name":"state","type":"Integer"},{"name":"publicKey","type":"PublicKey"}],"returntype":"Void","safe":false},{"name":"updateStateIR","offset":2280,"parameters":[{"name":"state","type":"Integer"},{"name":"publicKey","type":"PublicKey"}],"returntype":"Void","safe":false},{"name":"version","offset":4098,"parameters":[],"returntype":"Integer","safe":true}],"events":[{"name":"AddNode","parameters":[{"name":"publicKey","type":"PublicKey"},{"name":"addresses","type":"Array"},{"name":"attributes","type":"Map"}]},{"name":"AddPeerSuccess","parameters":[{"name":"publicKey","type":"PublicKey"}]},{"name":"UpdateStateSuccess","parameters":[{"name":"publicKey","type":"PublicKey"},{"name":"state","type":"Integer"}]},{"name":"NewEpoch","parameters":[{"name":"epoch","type":"Integer"}]},{"name":"NewEpochSubscription","parameters":[{"name":"contract","type":"Hash160"}]}]},"features":{},"groups":[],"permissions":[{"contract":"*","methods":["update","newEpoch"]}],"supportedstandards":[],"trusts":[],"extra":null}
6 changes: 4 additions & 2 deletions tests/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,10 @@ func TestContainerSizeEstimation(t *testing.T) {
newStorageNode(t, c),
}
for i := range nodes {
cNm.WithSigners(nodes[i].signer).Invoke(t, stackitem.Null{}, "addPeer", nodes[i].raw)
cNm.Invoke(t, stackitem.Null{}, "addPeerIR", nodes[i].raw)
var cAcc = new(neotest.ContractInvoker)
*cAcc = *cNm
cAcc.Signers = append(cAcc.Signers, nodes[i].signer)
cAcc.Invoke(t, stackitem.Null{}, "addPeer", nodes[i].raw)
}

// putContainerSize retrieves storage nodes from the previous snapshot,
Expand Down
14 changes: 9 additions & 5 deletions tests/netmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func TestAddPeer(t *testing.T) {
c := newNetmapInvoker(t)

acc := c.NewAccount(t)
cAcc := c.WithSigners(acc)
var cAcc = new(neotest.ContractInvoker)
*cAcc = *c
cAcc.Signers = append(cAcc.Signers, acc)
dummyInfo := dummyNodeInfo(acc)

acc1 := c.NewAccount(t)
Expand All @@ -95,12 +97,12 @@ func TestAddPeer(t *testing.T) {

h := cAcc.Invoke(t, stackitem.Null{}, "addPeer", dummyInfo.raw)
aer := cAcc.CheckHalt(t, h)
require.Equal(t, 0, len(aer.Events))
require.Equal(t, 1, len(aer.Events))

dummyInfo.raw[0] ^= 0xFF
h = cAcc.Invoke(t, stackitem.Null{}, "addPeer", dummyInfo.raw)
aer = cAcc.CheckHalt(t, h)
require.Equal(t, 0, len(aer.Events))
require.Equal(t, 1, len(aer.Events))

c.InvokeFail(t, common.ErrWitnessFailed, "addPeer", dummyInfo.raw)
c.Invoke(t, stackitem.Null{}, "addPeerIR", dummyInfo.raw)
Expand All @@ -122,8 +124,10 @@ func TestNewEpoch(t *testing.T) {

for i := range nodes {
for _, tn := range nodes[i] {
cNm.WithSigners(tn.signer).Invoke(t, stackitem.Null{}, "addPeer", tn.raw)
cNm.Invoke(t, stackitem.Null{}, "addPeerIR", tn.raw)
var cAcc = new(neotest.ContractInvoker)
*cAcc = *cNm
cAcc.Signers = append(cAcc.Signers, tn.signer)
cAcc.Invoke(t, stackitem.Null{}, "addPeer", tn.raw)
}

if i > 0 {
Expand Down

0 comments on commit 36adb10

Please sign in to comment.