Repository: bitcoin/bitcoin
File: src/kernel/context.h (C/C++)

Code before:
// Copyright (c) 2022 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_KERNEL_CONTEXT_H
#define BITCOIN_KERNEL_CONTEXT_H

#include <util/signalinterrupt.h>

#include <memory>

namespace kernel {
//! Context struct holding the kernel library's logically global state, and
//! passed to external libbitcoin_kernel functions which need access to this
//! state. The kernel library API is a work in progress, so state organization
//! and member list will evolve over time.
//!
//! State stored directly in this struct should be simple. More complex state
//! should be stored to std::unique_ptr members pointing to opaque types.
struct Context {
    Context();
    ~Context(); // NOLINT(performance-trivially-destructible)
};
} // namespace kernel

#endif // BITCOIN_KERNEL_CONTEXT_H


Review comment (suggestion):
In commit "kernel: Remove key module from kernel library" (a885a166cec6d84d08600f12b25d912bd28af80e)

Not directly related to this PR, but I think the code comment above is basically out of date. Initial idea for `kernel::Context` was to have it hold a collection of variables that kernel code needed to run, so kernel code could use the context struct instead of global variables, and application code would still be convenient to write.

But this was before Options structs were introduced, and currently code is only passing around options structs, not the Context struct as anticipated. So I think at this point it would be good describe the `kernel::Context` more accurately and probably make it a class instead of struct. Maybe:

```c++
//! RAII initializer for global kernel state, running initialization code that
//! should execute before other kernel code on construction, and running cleanup
//! meant to execute after other kernel code on destruction.
//!
//! This class initializes global state used by kernel code, including RNG and
//! SHA256 state. In the future, this could initialize more global state if more
//! globals are added, or become a no-op if globals are removed.
//!
//! Note: The `kernel::Context` class has a different role from `NodeContext`
//! and `WalletContext` structs, despite being similarly named. The kernel
//! context class is used to initialize global state, while the node and wallet
//! context structs are meant hold state themselves and remove the need for
//! global state.
class Context
```

Code after:
// Copyright (c) 2022 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_KERNEL_CONTEXT_H
#define BITCOIN_KERNEL_CONTEXT_H

namespace kernel {
//! Context struct holding the kernel library's logically global state, and
//! passed to external libbitcoin_kernel functions which need access to this
//! state. The kernel library API is a work in progress, so state organization
//! and member list will evolve over time.
//!
//! State stored directly in this struct should be simple. More complex state
//! should be stored to std::unique_ptr members pointing to opaque types.
struct Context {
    Context();
};
} // namespace kernel

#endif // BITCOIN_KERNEL_CONTEXT_H