Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitor in Chainstate #39

Merged
merged 9 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 36 additions & 19 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,28 @@ type (

// AppConfig is the configuration values and associated env vars
AppConfig struct {
Authentication *AuthenticationConfig `json:"authentication" mapstructure:"authentication"`
Cachestore *CachestoreConfig `json:"cache" mapstructure:"cache"`
Datastore *DatastoreConfig `json:"datastore" mapstructure:"datastore"`
Debug bool `json:"debug" mapstructure:"debug"`
DebugProfiling bool `json:"debug_profiling" mapstructure:"debug_profiling"`
DisableITC bool `json:"disable_itc" mapstructure:"disable_itc"`
Environment string `json:"environment" mapstructure:"environment"`
GDPRCompliance bool `json:"gdpr_compliance" mapstructure:"gdpr_compliance"`
GraphQL *GraphqlConfig `json:"graphql" mapstructure:"graphql"`
Mongo *datastore.MongoDBConfig `json:"mongodb" mapstructure:"mongodb"`
NewRelic *NewRelicConfig `json:"new_relic" mapstructure:"new_relic"`
Authentication *AuthenticationConfig `json:"authentication" mapstructure:"authentication"`
Cachestore *CachestoreConfig `json:"cache" mapstructure:"cache"`
Datastore *DatastoreConfig `json:"datastore" mapstructure:"datastore"`
Debug bool `json:"debug" mapstructure:"debug"`
DebugProfiling bool `json:"debug_profiling" mapstructure:"debug_profiling"`
DisableITC bool `json:"disable_itc" mapstructure:"disable_itc"`
Environment string `json:"environment" mapstructure:"environment"`
GDPRCompliance bool `json:"gdpr_compliance" mapstructure:"gdpr_compliance"`
GraphQL *GraphqlConfig `json:"graphql" mapstructure:"graphql"`
ImportBlockHeaders string `json:"import_block_headers" mapstructure:"import_block_headers"`
Mongo *datastore.MongoDBConfig `json:"mongodb" mapstructure:"mongodb"`
Monitor *MonitorOptions `json:"monitor" mapstructure:"monitor"`
NewRelic *NewRelicConfig `json:"new_relic" mapstructure:"new_relic"`
Notifications *NotificationsConfig `json:"notifications" mapstructure:"notifications"`
Paymail *PaymailConfig `json:"paymail" mapstructure:"paymail"`
Redis *RedisConfig `json:"redis" mapstructure:"redis"`
RequestLogging bool `json:"request_logging" mapstructure:"request_logging"`
Server *ServerConfig `json:"server" mapstructure:"server"`
SQL *datastore.SQLConfig `json:"sql" mapstructure:"sql"`
SQLite *datastore.SQLiteConfig `json:"sqlite" mapstructure:"sqlite"`
TaskManager *TaskManagerConfig `json:"task_manager" mapstructure:"task_manager"`
WorkingDirectory string `json:"working_directory" mapstructure:"working_directory"`
Paymail *PaymailConfig `json:"paymail" mapstructure:"paymail"`
Redis *RedisConfig `json:"redis" mapstructure:"redis"`
RequestLogging bool `json:"request_logging" mapstructure:"request_logging"`
Server *ServerConfig `json:"server" mapstructure:"server"`
SQL *datastore.SQLConfig `json:"sql" mapstructure:"sql"`
SQLite *datastore.SQLiteConfig `json:"sqlite" mapstructure:"sqlite"`
TaskManager *TaskManagerConfig `json:"task_manager" mapstructure:"task_manager"`
WorkingDirectory string `json:"working_directory" mapstructure:"working_directory"`
}

// AuthenticationConfig is the configuration for Authentication
Expand Down Expand Up @@ -95,6 +97,21 @@ type (
ServerPath string `json:"server_path" mapstructure:"server_path"` // server path i.e. "/graphql"
}

// MonitorOptions is the configuration for blockchain monitoring
MonitorOptions struct {
Debug bool `json:"debug" mapstructure:"debug"` // true/false
Enabled bool `json:"enabled" mapstructure:"enabled"` // true/false
CentrifugeServer string `json:"centrifuge_server" mapstructure:"centrifuge_server"` // The server url address
icellan marked this conversation as resolved.
Show resolved Hide resolved
Token string `json:"token" mapstructure:"token"` // Token to connect to the server with
icellan marked this conversation as resolved.
Show resolved Hide resolved
MonitorDays int `json:"monitor_days" mapstructure:"monitor_days"` // how many days in the past should we monitor an address (default: 7)
FalsePositiveRate float64 `json:"false_positive_rate" mapstructure:"false_positive_rate"` // how many false positives do we except (default: 0.01)
SaveTransactionDestinations bool `json:"save_transaction_destinations" mapstructure:"save_transaction_destinations"` // Whether to save destinations on monitored transactions
ProcessorType string `json:"processor_type" mapstructure:"processor_type"` // Type of processor to start monitor with. Default: bloom
LoadMonitoredDestinations bool `json:"load_monitored_destinations" mapstructure:"load_monitored_destinations"` // Whehter to load monitored destinations`
MaxNumberOfDestinations int `json:"max_number_of_destinations" mapstructure:"max_number_of_destinations"` // how many destinations can the filter hold (default: 100,000)
ProcessMempoolOnConnect bool `json:"process_mempool_on_connect" mapstructure:"process_mempool_on_connect"` // Whether to process all transactions in the mempool when connecting to centrifuge server
}

// NewRelicConfig is the configuration for New Relic
NewRelicConfig struct {
DomainName string `json:"domain_name" mapstructure:"domain_name"` // used for hostname display
Expand Down
8 changes: 8 additions & 0 deletions config/envs/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"transactions": false,
"uri": "mongodb://localhost:27017/xapi"
},
"monitor": {
icellan marked this conversation as resolved.
Show resolved Hide resolved
"enabled": true,
"centrifuge_server": "ws://localhost:8000/websocket",
"token": "",
"processMempoolOnConnect": true,
"load_monitored_destinations": false,
"save_destinations": true
},
"new_relic": {
"domain_name": "domain.com",
"enabled": false,
Expand Down
2 changes: 1 addition & 1 deletion config/envs/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"signing_disabled": false
},
"cache": {
"engine": "ristretto"
"engine": "freecache"
},
"datastore": {
"auto_migrate": true,
Expand Down
24 changes: 24 additions & 0 deletions config/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/BuxOrg/bux"
"github.com/BuxOrg/bux/cachestore"
"github.com/BuxOrg/bux/chainstate"
"github.com/BuxOrg/bux/datastore"
"github.com/BuxOrg/bux/taskmanager"
"github.com/BuxOrg/bux/utils"
Expand Down Expand Up @@ -138,6 +139,11 @@ func (s *AppServices) loadBux(ctx context.Context, appConfig *AppConfig) (err er
options = append(options, bux.WithITCDisabled())
}

// Set if the feature is disabled
if appConfig.ImportBlockHeaders != "" {
options = append(options, bux.WithImportBlockHeaders(appConfig.ImportBlockHeaders))
}

// todo: customize the logger

// todo: feature: override the config from JSON env (side-load your own /envs/custom-config.json
Expand Down Expand Up @@ -203,6 +209,24 @@ func (s *AppServices) loadBux(ctx context.Context, appConfig *AppConfig) (err er
options = append(options, bux.WithNotifications(appConfig.Notifications.WebhookEndpoint))
}

if appConfig.Monitor != nil && appConfig.Monitor.Enabled {
if appConfig.Monitor.CentrifugeServer == "" {
err = errors.New("CentrifugeServer is required for monitoring to work")
return
}
options = append(options, bux.WithMonitoring(ctx, &chainstate.MonitorOptions{
Debug: appConfig.Monitor.Debug,
CentrifugeServer: appConfig.Monitor.CentrifugeServer,
MonitorDays: appConfig.Monitor.MonitorDays,
Token: appConfig.Monitor.Token,
FalsePositiveRate: appConfig.Monitor.FalsePositiveRate,
MaxNumberOfDestinations: appConfig.Monitor.MaxNumberOfDestinations,
SaveTransactionDestinations: appConfig.Monitor.SaveTransactionDestinations,
LoadMonitoredDestinations: appConfig.Monitor.LoadMonitoredDestinations,
ProcessMempoolOnConnect: appConfig.Monitor.ProcessMempoolOnConnect,
}))
}

// Create the new client
s.Bux, err = bux.NewClient(ctx, options...)

Expand Down
2 changes: 0 additions & 2 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading