From b1063e66b90525da66b9dfa8cc9df3788282fa53 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 26 Jan 2021 20:48:25 +0300 Subject: [PATCH] [#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 --- container/config.yml | 8 ++++++ container/container_contract.go | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/container/config.yml b/container/config.yml index af3ebfa..75f3c49 100644 --- a/container/config.yml +++ b/container/config.yml @@ -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 diff --git a/container/container_contract.go b/container/container_contract.go index e298940..adfdb83 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -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 }