Skip to content

Commit

Permalink
[Tokenomics] Preparation for proportional relay mining rewards based …
Browse files Browse the repository at this point in the history
…on difficulty (#771)

## Summary

No real business logic changes, but preparation + tests + helpesr + TODOs for #781.

## Issue

- Preparation for #781
- Pre-requisite for #818

---------

Co-authored-by: Bryan White <[email protected]>
Co-authored-by: Redouane Lakrache <[email protected]>
  • Loading branch information
3 people authored Sep 21, 2024
1 parent 0b640a5 commit 35a7044
Show file tree
Hide file tree
Showing 37 changed files with 1,360 additions and 837 deletions.
259 changes: 133 additions & 126 deletions api/poktroll/tokenomics/event.pulsar.go

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,17 @@ func GetMaccPerms() map[string][]string {
}

// BlockedAddresses returns all the app's blocked account addresses.
// It is returned as a map for easy lookup, but is in essence a set.
func BlockedAddresses() map[string]bool {
result := make(map[string]bool)
blockedAddressSet := make(map[string]bool)
if len(blockAccAddrs) > 0 {
for _, addr := range blockAccAddrs {
result[addr] = true
blockedAddressSet[addr] = true
}
} else {
for addr := range GetMaccPerms() {
result[addr] = true
blockedAddressSet[addr] = true
}
}
return result
return blockedAddressSet
}
46 changes: 23 additions & 23 deletions docusaurus/docs/develop/contributing/observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ the memory usage and reduce the performance of the Prometheus server. To mitigat
```go
// Declare a named `error` return argument.
func (k msgServer) CreateClaim(...) (_ *types.MsgCreateClaimResponse, err error) {
// Declare claim to reference in telemetry.
var (
claim types.Claim
isExistingClaim bool
numRelays uint64
numComputeUnits uint64
)

// Defer telemetry calls so that they reference the final values the relevant variables.
defer func() {
// Only increment these metrics counters if handling a new claim.
if !isExistingClaim {
telemetry.ClaimCounter(types.ClaimProofStage_CLAIMED, 1, err)
telemetry.ClaimRelaysCounter(types.ClaimProofStage_CLAIMED, numRelays, err)
telemetry.ClaimComputeUnitsCounter(types.ClaimProofStage_CLAIMED, numComputeUnits, err)
}
}()
// Declare claim to reference in telemetry.
var (
claim types.Claim
isExistingClaim bool
numRelays uint64
numComputeUnits uint64
)

// Defer telemetry calls so that they reference the final values the relevant variables.
defer func() {
// Only increment these metrics counters if handling a new claim.
if !isExistingClaim {
telemetry.ClaimCounter(types.ClaimProofStage_CLAIMED, 1, err)
telemetry.ClaimRelaysCounter(types.ClaimProofStage_CLAIMED, numRelays, err)
telemetry.ClaimComputeUnitsCounter(types.ClaimProofStage_CLAIMED, numComputeUnits, err)
}
}()


// Ensure `err` is not shadowed by avoiding `:=` operator.
Expand All @@ -101,12 +101,12 @@ func (k msgServer) CreateClaim(...) (_ *types.MsgCreateClaimResponse, err error)
#### [x/tokenomics/module/abci.go](https://github.com/pokt-network/poktroll/blob/main/x/tokenomics/module/abci.go)
```go
// Emit telemetry for each service's relay mining difficulty.
for serviceId, newDifficulty := range difficultyPerServiceMap {
miningDifficultyNumBits := keeper.RelayMiningTargetHashToDifficulty(newDifficulty.TargetHash)
telemetry.RelayMiningDifficultyGauge(miningDifficultyNumBits, serviceId)
telemetry.RelayEMAGauge(newDifficulty.NumRelaysEma, serviceId)
}
// Emit telemetry for each service's relay mining difficulty.
for serviceId, newDifficulty := range difficultyPerServiceMap {
miningDifficultyNumBits := keeper.RelayMiningTargetHashToDifficulty(newDifficulty.TargetHash)
telemetry.RelayMiningDifficultyGauge(miningDifficultyNumBits, serviceId)
telemetry.RelayEMAGauge(newDifficulty.NumRelaysEma, serviceId)
}
```
### Histogram
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/0_settlement.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Feature: Tokenomics Namespace
Scenario: Settle the session when a valid claim is create but not required
# Baseline
Given the user has the pocketd binary installed
# Network preparation
# Network preparation and validation
And an account exists for "supplier1"
And the "supplier" account for "supplier1" is staked
And an account exists for "app1"
Expand Down
1 change: 0 additions & 1 deletion pkg/client/supplier/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func TestSupplierClient_SubmitProof(t *testing.T) {

// Generating an ephemeral tree & spec just so we can submit
// a proof of the right size.
// TODO_TECHDEBT(#446): Centralize the configuration for the SMT spec.
tree := smt.NewSparseMerkleSumTrie(kvStore, protocol.NewTrieHasher())
emptyPath := make([]byte, tree.PathHasherSize())
proof, err := tree.ProveClosest(emptyPath)
Expand Down
10 changes: 5 additions & 5 deletions pkg/client/tx/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tx_test

import (
"context"
"crypto/sha256"
"os"
"sync"
"testing"
Expand All @@ -22,6 +21,7 @@ import (
"github.com/pokt-network/poktroll/pkg/client"
"github.com/pokt-network/poktroll/pkg/client/keyring"
"github.com/pokt-network/poktroll/pkg/client/tx"
"github.com/pokt-network/poktroll/pkg/crypto/protocol"
"github.com/pokt-network/poktroll/pkg/either"
"github.com/pokt-network/poktroll/testutil/mockclient"
"github.com/pokt-network/poktroll/testutil/testclient"
Expand Down Expand Up @@ -364,6 +364,10 @@ func TestTxClient_SignAndBroadcast_Timeout(t *testing.T) {
txResultsBzPublishCh chan<- either.Bytes
blocksPublishCh = make(chan client.Block, tx.DefaultCommitTimeoutHeightOffset)
ctx = context.Background()

// Trie related variables
spec = smt.NewTrieSpec(protocol.NewTrieHasher(), true)
emptyBlockHash = make([]byte, spec.PathHasherSize())
)

keyring, signingKey := testkeyring.NewTestKeyringWithKey(t, testSigningKeyName)
Expand Down Expand Up @@ -415,10 +419,6 @@ func TestTxClient_SignAndBroadcast_Timeout(t *testing.T) {
err, errCh := eitherErr.SyncOrAsyncError()
require.NoError(t, err)

// TODO_TECHDEBT(#446): Centralize the configuration for the SMT spec.
spec := smt.NewTrieSpec(sha256.New(), true)
emptyBlockHash := make([]byte, spec.PathHasherSize())

for i := 0; i < tx.DefaultCommitTimeoutHeightOffset; i++ {
blocksPublishCh <- testblock.NewAnyTimesBlock(t, emptyBlockHash, int64(i+1))
}
Expand Down
46 changes: 0 additions & 46 deletions pkg/crypto/protocol/difficulty.go

This file was deleted.

106 changes: 0 additions & 106 deletions pkg/crypto/protocol/difficulty_test.go

This file was deleted.

Loading

0 comments on commit 35a7044

Please sign in to comment.