Commit Graph

18 Commits

Author SHA1 Message Date
Kittywhiskers Van Gogh
9f96723774
stats: stop using error codes, switch over to bool 2024-09-11 14:34:53 +00:00
Kittywhiskers Van Gogh
1a81979c1e
stats: initialize socket after we have a valid socket address
As creating the socket is now the last step, we don't need
`m_init` anymore. We can just see if a socket is successfully
constructed and take that as our validity indicator.

We'll also move it out of the inner `send` function so we can bail out
before we bother with all the string processing and manipulation.
2024-09-11 14:34:20 +00:00
Kittywhiskers Van Gogh
dbbfc8d766
stats: use Socks wrapper, use CService to generate our sockaddr 2024-09-11 14:34:20 +00:00
Kittywhiskers Van Gogh
2def905044
stats: move init logic into constructor
Also, add log messages to inform us if we're skipping initialization or
it has successfully been initialized.
2024-09-11 14:34:19 +00:00
Kittywhiskers Van Gogh
4bc727cd6c
stats: clean up randomization code, move FastRandomContext inward
We can skip the computationally expensive dice-roll if our sample rate
is zero as that means we should never send it. Also get rid of the
`FastRandomContext::operator()` that isn't used anywhere else in the
codebase.
2024-09-11 14:34:19 +00:00
Kittywhiskers Van Gogh
840241eefd
stats: cleanup error logging, improve code sanity
- Use `uint16_t` instead of `short`, `int64_t` instead of `size_t`
- Get rid of the `errmsg` buffer and use `LogPrintf` to report errors
- Use `strprintf` instead of `snprintf`
- Rephrase networking error logs to allow inclusion of error strings
2024-09-11 14:33:55 +00:00
Kittywhiskers Van Gogh
85890ddb13
docs: add copyright notice to source file, update notice in header 2024-09-06 19:08:19 +00:00
Kittywhiskers Van Gogh
a9d1b1494d
stats: move _StatsdClientData variables into StatsdClient
There doesn't seem to be a benefit to keeping these values in a separate
struct.
2024-09-06 19:08:19 +00:00
Kittywhiskers Van Gogh
30c30c1397
stats: fetch all arguments needed when constructing g_stats_client
There's little sense in passing a ref to `ArgsManager` just to set a few
values because we'll be `const`-ing them in an upcoming commit.
Arguments supplied are expected to last the lifetime of the program's
instance and there's little reason to keep re-fetching those values.
2024-09-06 19:08:19 +00:00
Kittywhiskers Van Gogh
5133d88415
stats: s/statsClient/g_stats_client/g 2024-09-06 19:08:19 +00:00
Kittywhiskers Van Gogh
f81951dd00
stats: make statsClient a std::unique_ptr, denote as global variable
This step is needed so we can simplify construction in an upcoming
commit
2024-09-06 19:08:19 +00:00
Konstantin Akimov
add99ea862
refactor: add more consts everywhere as required by cppcheck 2.13.0 2024-03-06 03:31:48 +07:00
Konstantin Akimov
097a8e7196
non-scripted-diff: bump copyright year to 2023
that's a result of:
contrib/devtools/copyright_header.py update ./

it is not scripted diff, because it works differentlly on my localhost and in CI:
CI doesn't want to use git commit date which is mocked to 30th Dec of 2023
2024-02-24 11:05:37 -06:00
UdjinM6
828fac4c14 chore: add missing copyrights via copyright_header.py insert 2023-01-13 00:49:04 +03:00
PastaPastaPasta
ad88fab80d
test/refactor: upgrade to cppcheck 2.9 and fix warnings (#5049)
* refactor: resolve warnings thrown by cppcheck 2.9

* test: upgrade cppcheck to version 2.9
2022-10-18 13:24:00 +03:00
PastaPastaPasta
f503a7edc1
refactor: Fix warnings from cppcheck (#4625)
* src/evo/evodb.cpp:57:29: warning: Assert statement calls a function which may have desired side effects: 'IsClean'. [assertWithSideEffect]

* src/llmq/quorums.cpp:635:37: note: Null pointer dereference

src/llmq/quorums.cpp:635:37: warning: Either the condition 'pFrom==nullptr' is redundant or there is possible null pointer dereference: pFrom. [nullPointerRedundantCheck]
src/llmq/quorums.cpp:636:81: note: Assuming that condition 'pFrom==nullptr' is not redundant

* fix a bunch of cppcheck warnings

* cppcheck: run on many more files. Enable all checks except a few ignored ones.

ignored
```
    "Consider using std::transform algorithm instead of a raw loop."
    "Consider using std::accumulate algorithm instead of a raw loop."
```

* ci: build specific version of cppcheck instead of install from apt

* ci: use cppcheck 2.4, remove commented out line, fix symlink

cppcheck 2.6 is latest, however causes issues
```
src/spork.cpp:135:51: warning: Analysis failed. If the code is valid then please report this failure. [cppcheckError]
```
cppcheck 2.5 appears to get into an infinite loop

* no need to check presence before insertion

* use if-init, remove redundant check

* remove redundant check

* don't remove cmake? fix macOs depends build?

* cppcheck: one per line, alphabetize

* remove duplicate cmake install
2021-12-29 00:54:50 +03:00
PastaPastaPasta
91f4e71563
trivial: misc. trivial refactoring (#4104)
* minor statsd refactoring

* stacktrace refactoring

* spork typos + unused include

* need thread on windows builds
2021-04-15 13:58:04 -04:00
UdjinM6
b559a8f904
Backporting Statoshi and bitcoin#16728 (#2515)
* Backport Statoshi

This backports some of https://github.com/jlopp/statoshi.

Missing stuff: README.md and client name changes, segwit and fee estimation stats.

Fix RejectCodeToString

Fix copy-paste mistake s/InvalidBlockFound/InvalidChainFound/

* Merge #16728: move-only: move coins statistics utils out of RPC

8a3b2eb17572ca2131778d52cc25ec359470a90f move-only: move coins statistics utils out of RPC (James O'Beirne)

Pull request description:

  This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11):

  Parent PR: #15606
  Issue: #15605
  Specification: https://github.com/jamesob/assumeutxo-docs/tree/master/proposal

  ---

  In the short-term, this move-only commit will help with fuzzing (https://github.com/bitcoin/bitcoin/pull/15606#issuecomment-524482297). Later, these procedures will be used to compute statistics (particularly a content hash) for UTXO sets coming in from snapshots.

  Most easily reviewed with `git ... --color-moved=dimmed_zebra`. A nice follow-up would be adding unittests, which I'll do if nobody else gets around to it.

ACKs for top commit:
  MarcoFalke:
    ACK 8a3b2eb17572ca2131778d52cc25ec359470a90f, checked --color-moved=dimmed-zebra

Tree-SHA512: a187d2f7590ad2450b8e8fa3d038c80a04fc3d903618c24222d7e3172250ce51badea35860c86101f2ba266eb4354e6efb8d7d508b353f29276e4665a1efdf74

* Fix 16728

* Modernize StatsdClient

- Reuse some functionality from netbase
- Switch from GetRand to FastRandomContext
- Drop `using namespace std` and add `// namespace statsd`

* Introduce PeriodicStats and make StatsdClient configurable via -stats<smth> (enabled/host/port/ns/period)

* Move/rename tip stats from CheckBlock to ConnectBlock

* Add new false positives to lint-format-strings.py

* Add snprintf in statsd_client to the list of known violations in lint-locale-dependence.sh

* Fix incorrect include guard

* Use bracket syntax includes

* Replace magic numbers with defaults

* Move connection stats calculation into its own function

And bail out early if stats are disabled

* assert in PeriodicStats

Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>

Co-authored-by: MarcoFalke <falke.marco@gmail.com>
Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>
2020-12-15 10:22:23 -06:00