Comments (13)
I would STRONGLY suggest not implementing any security, as doing so requires ADDITIONAL design decisions to be implemented, like scripting rules.
Part of the reason I was attracted to this project is that it's 'pure' from an implementation perspective: It's just a blockchain implementation, untainted by opinionated solutions.
If you want to start making it more opinionated, make a new project and build on it, but leave this as is so it can be what it was intended to be: A blockchain implementation and nothing more.
from naivechain.
It's nice to see that people are interested to augment the initial version of naivechain, which has many flaws, one of them being the lack of PoW/PoS.
I spent long hours with a PoW of implementation on naivechain just to eventually disregard it. I couldn't fit it in the 200 lines of code, which was my primary goal. It also made things more complex.
To introduce PoW you should in my opinion introduce at least the following
-Adding the PoW function
-Difficulty adjustment on the network
-Choosing the longest chain must be based on the "difficulty" of blockchain
I intend to keep the original singe-file version of naivechain as the main version. You can fork the naivechain and augment it any way you like. I can add links to your repos on README.md, if you create any augmented versions of naivechain that have new features.
from naivechain.
I'm okay with the fact that the code does not implement a PoW scheme;
but I suggest refactoring the Code (into Classes) from which a new set of classes are derived that implement a simple PoW scheme.
It would then be possible to derive another set of classes that implement a Proof of Stake scheme.
from naivechain.
I would suggest implementing naivechain-pow
as a separate module that naivechain
can use or not 😄
from naivechain.
Hey guys I was reading about block chain and i found a video that give example of implementing proof of work in block chain. May be this could help.
https://www.youtube.com/watch?v=HneatE69814
from naivechain.
I actually started some refactoring on this myself, but found it quite hard to make it more grokkable than it already is. The one thing that could/should be moved out of main.js
is the http
code (as @antony mentions). It's not really relevant and would force exposure of relevant functions. imho.
from naivechain.
I actually created project called Naivecoin. It is an extension to Naivechain and it implements e.g. Proof-of-Work. You can find it here: https://lhartikk.github.io/
from naivechain.
@andreaskern I've done some refactoring in #3 which will hopefully make adding a PoW scheme easier. Let me know what you think.
from naivechain.
@TSavo I agree with you, the a naive implementation should always only be the naive blockchain and for ease of reading, everything should be kept in a single file.
While reading the source code I asked myself "Would it be difficult to include PoW?" and the answer would be "No". In a quick thought experiment I came up with ~4 loc to be added/changed for PoW. But those lines would definitely make it harder to comprehend.
The goal is to make the naive implementation easy to extend to PoW or PoS without compromising the readability.
@antony There is a lot of stuff in the refactoring I like, (e.g. putting the block hash functions inside the block class). It definitely is more enterprise ready, though loses on the educational side. it extracts the blockchain part which is ~93 sloc but it overall it adds ~87 sloc. It definitely adds complexity. For the educational aspect I'm in favor of increasing readability
from naivechain.
@andreaskern thanks - and I fundamentally agree that a single file is more grokkable, however I think that, for instance, having to have the http api stuck in the middle of the blockchain code actually decreases readability.
There is also a lot of variable tracing which is harder if things aren't separated out, whereas now I can go oh- that variable relates to inter-process messaging, and is not part of how a blockchain works.
Also the number 1 way to make code understandable is to write tests - a living documentation for the source, and that's just not feasible in a single-file - you can't mock things out, so setup code will be huge. In fact I'm pretty sure I've found a bug in blockchain validation here - I don't think this code will return false from the parent method when an invalid block is found: https://github.com/lhartikk/naivechain/blob/master/main.js#L179
Therefore I feel that some degree of separation is required - the blockchain implementation is entirely contained in the 'blockchain' class, which means that if I want to understand how a blockchain works I can do so, without worrying about websockets, messaging, or http servers, I can - that's why I did it in fact. I needed clarity around a blockchain implementation.
from naivechain.
Works for me - If you don't mind linking my version as a 'class based' version or something, that would be great :)
from naivechain.
Can someone provide the link to the repo with added functionality in Naive Chain?
from naivechain.
got it @lhartikk
from naivechain.
Related Issues (20)
- Crptojs SHA256 function error HOT 3
- Unknown Errors HOT 2
- Upgrade Required HOT 4
- Is it Blockchain implementation ?
- Average time of adding a block to the blockchain
- Questions about spreading fake long blockchain from “bad” nodes HOT 2
- Quick start not working..help! HOT 3
- blockchain invalid error when syncing a longer blockchain HOT 4
- how to add hash difficulty ?
- Data lost if nodes fails to connect to known peers
- How can I get an specific block?
- how to start this project if i use windows? HOT 1
- Prototype Override Protection Bypass
- Regular Expression Denial of Service (DoS)
- Regular Expression Denial of Service (ReDoS)
- Regular Expression Denial of Service (ReDoS) # 2
- Received blockchain is not longer than current Blockchain. Do Nothing
- 403 err
- 1684 W Berkshire Ln
- 1684 W Berkshire Ln HOT 1
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 naivechain.