[#41] container: Produce notification to control container estimations

Basic income settlements depends on container estimation that
should be collected in P2P communication between storage nodes
and then stored in container contract. To synchronize these
actions there are two separate notification that inner ring
should produce in consensus.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
enable-notary-in-public-chains
Alex Vanin 2021-01-26 20:48:25 +03:00 committed by Alex Vanin
parent a04d9b7e70
commit b1063e66b9
2 changed files with 56 additions and 0 deletions

View File

@ -15,3 +15,11 @@ events:
type: ByteArray
- name: signature
type: ByteArray
- name: StartEstimation
parameters:
- name: epoch
type: Integer
- name: StopEstimation
parameters:
- name: epoch
type: Integer

View File

@ -372,6 +372,54 @@ func ProcessEpoch(epochNum int) {
}
}
func StartContainerEstimation(epoch int) bool {
netmapContractAddr := storage.Get(ctx, netmapContractKey).([]byte)
innerRing := contract.Call(netmapContractAddr, "innerRingList").([]irNode)
threshold := len(innerRing)/3*2 + 1
irKey := innerRingInvoker(innerRing)
if len(irKey) == 0 {
panic("startEstimation: only inner ring nodes can invoke this")
}
hashCandidate := invokeID([]interface{}{epoch}, []byte("startEstimation"))
n := vote(ctx, hashCandidate, irKey)
if n >= threshold {
removeVotes(ctx, hashCandidate)
runtime.Notify("StartEstimation", epoch)
runtime.Log("startEstimation: notification has been produced")
} else {
runtime.Log("startEstimation: processed invoke from inner ring")
}
return true
}
func StopContainerEstimation(epoch int) bool {
netmapContractAddr := storage.Get(ctx, netmapContractKey).([]byte)
innerRing := contract.Call(netmapContractAddr, "innerRingList").([]irNode)
threshold := len(innerRing)/3*2 + 1
irKey := innerRingInvoker(innerRing)
if len(irKey) == 0 {
panic("stopEstimation: only inner ring nodes can invoke this")
}
hashCandidate := invokeID([]interface{}{epoch}, []byte("stopEstimation"))
n := vote(ctx, hashCandidate, irKey)
if n >= threshold {
removeVotes(ctx, hashCandidate)
runtime.Notify("StopEstimation", epoch)
runtime.Log("stopEstimation: notification has been produced")
} else {
runtime.Log("stopEstimation: processed invoke from inner ring")
}
return true
}
func Version() int {
return version
}