Comments (6)
Proposal is
export (ChainId,mkChainId) -- private constructor
...
data ChainId = ChainId ChainwebVersion Word32 deriving (Ord...) -- not sure if Ord is a necc. feature of current ChainId
mkChainId :: MonadThrow m => ChainwebVersion Word32 -> m ChainId
from chainweb-node.
In the API, ChainwebVersion
and ChainId
should go into separate path segments because not all chainweb Resources are chain-resources. So, not all resources have a ChainId
, but all have a ChainwebVersion
.
So path should still look like .../Testnet00/chain/0/...
. This expresses that a chain id can only occur in the scope of a Chainweb version.
from chainweb-node.
I propose that instead of changing the existing ChainId
newtype, we introduce a new product type, say, ChainwebChainId
, that holds a ChainId
and a ChainwebVersion
.
We have already a HasChainwebVersion
type class. Most chain resources are instances of it (e.g. BlockHeader, TreeDB, BlockHeaderDB). The new type that this issue proposes should be an instance of this class.
Component APIs should use the new ChainwebChainId
type. An example would be selecting the source chain in the SPV API. Also, the the public getter for the chain id of a block header (or other data types that contain chain ids) should return this type.
In the chainweb consensus code base we still need the "bare" ChainId
newtype and I propose to not change that type, because it is used in many places. Instead, I propose to limit its usage to internal, low-level APIs. It would be costly, both on the heap and in serializations to always replicate the chainweb version. It would also slow down code that uses maps that are indexed with chain ids, like, for instance cuts, and vectors of adjacent parent hashes. For data structures that contain those maps it still makes sense to store the chainweb version only once. The public Getter's should still return the "safe" ChainwebChainId
type with the HasChainwebVersion
instance.
from chainweb-node.
I propose the following change, that allows for a less intrusive implementation.
export (ChainwebChainId,mkChainwebChainId) -- private constructor
...
data ChainwebChainId = ChainwebChainId ChainwebVersion ChainId
mkChainwebChainId :: MonadThrow m => ChainwebVersion ChainId -> m ChainwebChainId
mkChainwebChainId_ :: MonadThrow m => ChainwebVersion Word32 -> m ChainwebChainId
Possibly only one smart constructor is needed.
This also doesn't require to derive all instances that current low-level code requires for ChainId
.
In addition the constructor of BlockHeader should be made private (something that we were planning since a while but didn't do to not disturb work on Testnet) and blockChainId
should return ChainwebChainId
. Other component API types and functions that expose ChainId
should be change analogously.
from chainweb-node.
I think that the default way to obtain values of type ChainId
in production code, should be either
- via
chainIds_ $ _chainGraph version
, or - via validated deserialization (e.g. as part of block headers).
Outside of testing, it should rarely be a need to create a chain id value out of thin air.
In fact, unsafeChainId
is currently used only in very places. It's legitimately used in ea
and Chainweb.Graph
. Otherwise it is used only in test code. Therefor the main use of the new "safe" chain id type would probably be in pact when a user selects a chain for SPV transactions.
from chainweb-node.
It would seem this is mainly for REST API endpoints, which we still need to have a discussion about to handle hardforks. Closing for now.
from chainweb-node.
Related Issues (20)
- The log needs to support the logrotate mechanism. HOT 6
- Broken link on main github page HOT 1
- New rocksdb-haskell-kadena dependency does not build on macOS
- Add nix-build to CI for chainweb-node HOT 2
- Link to the whitepaper in the repository description goes to "Page Not Found" HOT 2
- The program won't start, what should I do? HOT 3
- fix server startup in `Chainweb.Chainweb` (make sure exception in server are propagated).
- On-chain error reporting should be restored HOT 16
- GNU/Linux Debian 11 - 5.19.0-0.deb11.2-amd64 - build error - cabal: Error parsing project freeze file HOT 4
- Incorrect Whitepaper link in "About" Section HOT 1
- Transactions often "idle" for several blocks before being included HOT 3
- Gas Errors Are Unhelpful HOT 5
- DoS Attack Potential Using gasLimit HOT 6
- Mempool Transaction Propagation HOT 13
- Trying to build on Mac M1 fails with "Could not resolve dependencies" HOT 3
- How to obtain the ubuntu binary? HOT 4
- Node unable to reach bootstrap peers HOT 3
- nix-build no longer works as of latest release 2.19/2.19.1 HOT 5
- cabal install fails as of 2.19/2.19.1 HOT 8
- chainweb-node crashes from time to time HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chainweb-node.