-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19452f4
commit 27541e9
Showing
15 changed files
with
1,507 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/ODIN-PROTOCOL/odin-core/kvasir" | ||
) | ||
|
||
func main() { | ||
kvasir.Main() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package kvasir | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func configCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "config [key] [value]", | ||
Aliases: []string{"c"}, | ||
Short: "Set kvasir configuration environment", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
viper.Set(args[0], args[1]) | ||
return viper.WriteConfig() | ||
}, | ||
} | ||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package kvasir | ||
|
||
import ( | ||
"sync/atomic" | ||
"time" | ||
|
||
"github.com/ODIN-PROTOCOL/odin-core/kvasir/executor" | ||
wasmtypes "github.com/ODIN-PROTOCOL/wasmd/x/wasm/types" | ||
rpcclient "github.com/cometbft/cometbft/rpc/client" | ||
"github.com/cosmos/cosmos-sdk/crypto/keyring" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
type Request struct { | ||
ChosenValidators []string `json:"chosen_validators"` | ||
Metadata string `json:"metadata"` | ||
PartsReceived uint32 `json:"parts_received"` | ||
PartsRequested uint32 `json:"parts_requested"` | ||
Payed sdk.Coins `json:"payed"` | ||
RequestHeight uint64 `json:"request_Height"` | ||
RequestID uint64 `json:"request_id"` | ||
Sender string `json:"sender"` | ||
Status string `json:"status"` | ||
} | ||
|
||
type RequestKey struct { | ||
ContractAddress string | ||
RequestID uint64 | ||
} | ||
|
||
type ReportMsgWithKey struct { | ||
result []byte | ||
contractAddress string | ||
msg *wasmtypes.RawContractMessage | ||
execVersion string | ||
keyIndex int64 | ||
requestID uint64 | ||
} | ||
|
||
type Context struct { | ||
client rpcclient.Client | ||
validator sdk.ValAddress | ||
validatorAccAddr sdk.AccAddress | ||
gasPrices string | ||
keys []*keyring.Record | ||
executor executor.Executor | ||
broadcastTimeout time.Duration | ||
maxTry uint64 | ||
rpcPollInterval time.Duration | ||
maxReport uint64 | ||
ipfs string | ||
grpc *grpc.ClientConn | ||
|
||
pendingMsgs chan ReportMsgWithKey | ||
freeKeys chan int64 | ||
keyRoundRobinIndex int64 // Must use in conjunction with sync/atomic | ||
|
||
pendingRequests map[RequestKey]bool | ||
|
||
contracts []string | ||
|
||
metricsEnabled bool | ||
handlingGauge int64 | ||
pendingGauge int64 | ||
errorCount int64 | ||
submittedCount int64 | ||
home string | ||
} | ||
|
||
func (c *Context) nextKeyIndex() int64 { | ||
keyIndex := atomic.AddInt64(&c.keyRoundRobinIndex, 1) % int64(len(c.keys)) | ||
return keyIndex | ||
} | ||
|
||
func (c *Context) updateHandlingGauge(amount int64) { | ||
if c.metricsEnabled { | ||
atomic.AddInt64(&c.handlingGauge, amount) | ||
} | ||
} | ||
|
||
func (c *Context) updatePendingGauge(amount int64) { | ||
if c.metricsEnabled { | ||
atomic.AddInt64(&c.pendingGauge, amount) | ||
} | ||
} | ||
|
||
func (c *Context) updateErrorCount(amount int64) { | ||
if c.metricsEnabled { | ||
atomic.AddInt64(&c.errorCount, amount) | ||
} | ||
} | ||
|
||
func (c *Context) updateSubmittedCount(amount int64) { | ||
if c.metricsEnabled { | ||
atomic.AddInt64(&c.submittedCount, amount) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package kvasir | ||
|
||
import ( | ||
abci "github.com/cometbft/cometbft/abci/types" | ||
) | ||
|
||
type rawRequest struct { | ||
contract string | ||
requestID uint64 | ||
calldata string | ||
} | ||
|
||
// GetEventValues returns the list of all values in the given log with the given type and key. | ||
func GetEventValues(log []abci.Event, evType string, evKey string) (res []string) { | ||
for _, ev := range log { | ||
if ev.Type != evType { | ||
continue | ||
} | ||
|
||
for _, attr := range ev.Attributes { | ||
if attr.Key == evKey { | ||
res = append(res, attr.Value) | ||
} | ||
} | ||
} | ||
return res | ||
} |
Oops, something went wrong.