diff --git a/config/config.mainnet.toml b/config/config.mainnet.toml deleted file mode 100644 index 3a715b1b..00000000 --- a/config/config.mainnet.toml +++ /dev/null @@ -1,94 +0,0 @@ -[blockchain] -bonding_denom = "basecro" -account_address_prefix = "cro" -account_pubkey_prefix = "cro" -validator_address_prefix = "crocncl" -validator_pubkey_prefix = "crocncl" -connode_address_prefix = "crocnclcons" -connode_pubkey_prefix = "crocnclconspub" - -[cosmos_version_enabled_height] -# chain-maind v2.x.x starting height in mainnet -v0_42_7 = 922362 - -[system] -# mode of the system, possible values: EVENT_STORE,TENDERMINT_DIRECT -# EVENT_STORE mode: synced blocks are parsed to events and persist to event store. Projections will replay events from -# event store. -# TENDERMINT_DIRECT mode: synced blocks are parsed to events and are replayed directly by projections. -# API_ONLY mode: indexing is disabled and provide API service only -mode = "TENDERMINT_DIRECT" - -[sync] -# how many sync jobs running in parallel -window_size = 50 - -[tendermint] -http_rpc_url = "https://mainnet.crypto.org:26657" -insecure = false -# When enabled, genssi parsing will reject any non-Cosmos SDK built-in module -# inside genesis file. -strict_genesis_parsing = false - -[cosmosapp] -http_rpc_url = "https://mainnet.crypto.org:1317" -insecure = false - -[http] -listening_address = "0.0.0.0:8080" -route_prefix = "/" -# A list of origins a cross-domain request is allowed to be requested from -# Default value '[]' disables CORS support -# Use '["*"]' to allow request from any origin -cors_allowed_origins = [] -cors_allowed_methods = ["HEAD", "GET"] -cors_allowed_headers = ["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time"] - -[debug] -pprof_enable = false -pprof_listening_address = "0.0.0.0:3000" - -[database] -host = "localhost" -port = 5432 -username = "postgres" -# password can only be provided through CLI or Environment variable `DB_PASSWORD` -name = "postgres" -schema = "public" -ssl = true - -[postgres] -pool_max_conns = 100 -pool_min_conns = 0 -pool_max_conn_lifetime = "1h" -pool_max_conn_idle_time = "30m" -pool_health_check_interval = "1m" - -[logger] -# comma separated log levels. possible values: debug,info,error,panic -level = "debug" -color = false - -[projection] -enables = [ - "AccountMessage", - "AccountTransaction", - "Block", - "BlockEvent", - "ChainStats", - "Proposal", - "Transaction", - "Validator", - "ValidatorStats", - "NFT", -# "CryptoComNFT", - "IBCChannel", -# "IBCChannelTxMsgTrace", - "IBCChannelMessage", -# "BridgePendingActivity" -] - -[cronjob] -enables = [ -# "BridgeActivityMatcher" -] diff --git a/projection/validator/validator.go b/projection/validator/validator.go index f7d8fdd5..d10d3ec4 100644 --- a/projection/validator/validator.go +++ b/projection/validator/validator.go @@ -193,6 +193,7 @@ func (projection *Validator) HandleEvents(height int64, events []event_entity.Ev return fmt.Errorf("error querying active validators: %v", activeValidatorsQueryErr) } + var mutActiveValidators []view.ValidatorRow for _, activeValidator := range activeValidators { mutActiveValidator := activeValidator if commitmentMap[mutActiveValidator.ConsensusNodeAddress] { @@ -210,9 +211,11 @@ func (projection *Validator) HandleEvents(height int64, events []event_entity.Ev new(big.Float).SetInt64(mutActiveValidator.TotalActiveBlock), ) - if activeValidatorUpdateErr := validatorsView.Update(&mutActiveValidator); activeValidatorUpdateErr != nil { - return fmt.Errorf("error updating active validators up time data: %v", activeValidatorUpdateErr) - } + mutActiveValidators = append(mutActiveValidators, mutActiveValidator) + } + + if activeValidatorUpdateErr := validatorsView.UpdateAllValidatorUpTime(mutActiveValidators); activeValidatorUpdateErr != nil { + return fmt.Errorf("error updating active validators up time data: %v", activeValidatorUpdateErr) } } else if votedEvent, ok := event.(*event_usecase.MsgVote); ok { diff --git a/projection/validator/view/validators.go b/projection/validator/view/validators.go index 55e973a5..97e1c2fd 100644 --- a/projection/validator/view/validators.go +++ b/projection/validator/view/validators.go @@ -241,6 +241,64 @@ func (validatorsView *Validators) Update(validator *ValidatorRow) error { return nil } +func (validatorsView *Validators) UpdateAllValidatorUpTime(validators []ValidatorRow) error { + + pendingRowCount := 0 + totalRowCount := len(validators) + + sql := "" + + for i, validator := range validators { + + if pendingRowCount == 0 { + + sql = `UPDATE view_validators AS view SET + total_signed_block = row.total_signed_block, + total_active_block = row.total_active_block, + imprecise_up_time = row.imprecise_up_time + FROM (VALUES + ` + } + + sql += fmt.Sprintf( + "(%d, %d, %d, %s),\n", + *validator.MaybeId, + validator.TotalSignedBlock, + validator.TotalActiveBlock, + validator.ImpreciseUpTime.String(), + ) + + pendingRowCount += 1 + + if pendingRowCount == 500 || i+1 == totalRowCount { + + sql = strings.TrimSuffix(sql, ",\n") + + sql += `) AS row( + id, + total_signed_block, + total_active_block, + imprecise_up_time + ) + WHERE row.id = view.id;` + + result, err := validatorsView.rdb.Exec(sql) + if err != nil { + return fmt.Errorf("error updating validators up time into the table: %v: %w", err, rdb.ErrWrite) + } + if result.RowsAffected() != int64(pendingRowCount) { + return fmt.Errorf("error updating validators up time into the table: wrong number of affected rows %d: %w", result.RowsAffected(), rdb.ErrWrite) + } + + pendingRowCount = 0 + + } + + } + + return nil +} + type ValidatorsListFilter struct { MaybeStatuses []constants.Status }