Skip to content

Commit

Permalink
feat: allow disabling consensus WAL (gnolang#1723)
Browse files Browse the repository at this point in the history
<!-- please provide a detailed description of the changes made in this
pull request. -->
This allows for the consensus state's WAL to be disabled. This is
desirable for testing against a running node when we don't care about
the WAL -- it avoids potential permissions issues by not writing
anything to disk. This allows for our integration testing package to be
imported and used outside of the gno repository.
<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Co-authored-by: Morgan <[email protected]>
  • Loading branch information
deelawn and thehowl authored Mar 8, 2024
1 parent d8277e4 commit 45c8f90
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions gno.land/pkg/integration/testing_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func DefaultTestingTMConfig(gnoroot string) *tmcfg.Config {
const defaultListner = "tcp://127.0.0.1:0"

tmconfig := tmcfg.TestConfig().SetRootDir(gnoroot)
tmconfig.Consensus.WALDisabled = true
tmconfig.Consensus.CreateEmptyBlocks = true
tmconfig.Consensus.CreateEmptyBlocksInterval = time.Duration(0)
tmconfig.RPC.ListenAddress = defaultListner
Expand Down
11 changes: 6 additions & 5 deletions tm2/pkg/bft/consensus/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const (
// ConsensusConfig defines the configuration for the Tendermint consensus service,
// including timeouts and details about the WAL and the block structure.
type ConsensusConfig struct {
RootDir string `toml:"home"`
WalPath string `toml:"wal_file"`
walFile string // overrides WalPath if set
RootDir string `toml:"home"`
WALPath string `toml:"wal_file"`
WALDisabled bool `toml:"-"`
walFile string // overrides WalPath if set

TimeoutPropose time.Duration `toml:"timeout_propose"`
TimeoutProposeDelta time.Duration `toml:"timeout_propose_delta"`
Expand All @@ -43,7 +44,7 @@ type ConsensusConfig struct {
// DefaultConsensusConfig returns a default configuration for the consensus service
func DefaultConsensusConfig() *ConsensusConfig {
return &ConsensusConfig{
WalPath: filepath.Join(defaultDataDir, "cs.wal", "wal"),
WALPath: filepath.Join(defaultDataDir, "cs.wal", "wal"),
TimeoutPropose: 3000 * time.Millisecond,
TimeoutProposeDelta: 500 * time.Millisecond,
TimeoutPrevote: 1000 * time.Millisecond,
Expand Down Expand Up @@ -111,7 +112,7 @@ func (cfg *ConsensusConfig) WalFile() string {
if cfg.walFile != "" {
return cfg.walFile
}
return join(cfg.RootDir, cfg.WalPath)
return join(cfg.RootDir, cfg.WALPath)
}

// SetWalFile sets the path to the write-ahead log file
Expand Down
4 changes: 3 additions & 1 deletion tm2/pkg/bft/consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ type ConsensusState struct {
// a Write-Ahead Log ensures we can recover from any kind of crash
// and helps us avoid signing conflicting votes
wal walm.WAL
walDisabled bool
replayMode bool // so we don't log signing errors during replay
doWALCatchup bool // determines if we even try to do the catchup

Expand Down Expand Up @@ -162,6 +163,7 @@ func NewConsensusState(
doWALCatchup: true,
evsw: events.NewEventSwitch(),
wal: walm.NopWAL{},
walDisabled: config.WALDisabled,
}
// set function defaults (may be overwritten before calling Start)
cs.decideProposal = cs.defaultDecideProposal
Expand Down Expand Up @@ -294,7 +296,7 @@ func (cs *ConsensusState) OnStart() error {

// we may set the WAL in testing before calling Start,
// so only OpenWAL if its still the walm.NopWAL
if _, ok := cs.wal.(walm.NopWAL); ok {
if _, ok := cs.wal.(walm.NopWAL); ok && !cs.walDisabled {
walFile := cs.config.WalFile()
wal, err := cs.OpenWAL(walFile)
if err != nil {
Expand Down

0 comments on commit 45c8f90

Please sign in to comment.