oasisprotocol / oasisprotocol/oasis-core

updateCached should return (api.EpochTime, bool) to avoid apparent race condition

Open
#2,134 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
369
Forks
151
Avg merge
1d 3h
Merged PRs (30d)
6

Description

Description of the bug

Ultra tiny nit.

https://github.com/oasislabs/ekiden/blob/2cb41bfab18c7e34288e476b3a7a3f12fbb7fd47/go/epochtime/tendermint/tendermint.go#L80

https://github.com/oasislabs/ekiden/blob/2cb41bfab18c7e34288e476b3a7a3f12fbb7fd47/go/epochtime/tendermint/tendermint.go#L74

If updateCached were to return (api.EpochTime, bool) instead of just the bool, then we would not need the comment on L74 since the apparent data race does not occur. There is only one goroutine thread running worker() and everything should be fine in all practical concurrency models, but this is potential a future false positive if/when we get a data race analyzer, so we might as well avoid it by using a nicer method signature.

Steps to reproduce

  1. Read the code.

Expected behavior
In all possible futures where we get a race condition detectors / code analyzers (tsan-like tool for golang), they will not complain about this code, even if the analyzers were not very smart. 😄

Environment

  • OS:
  • Versions of relevant software and tools:

Additional information

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read go/epochtime/tendermint/tendermint.go at the referenced updateCached and worker locations, then trace how updateCached's return value is used. Change the signature and its caller so the cached EpochTime is returned with the boolean, and verify that the comment about the apparent race is no longer needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
blockchain
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.