Git Product home page Git Product logo

Comments (13)

TSavo avatar TSavo commented on July 20, 2024 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.

lhartikk avatar lhartikk commented on July 20, 2024 6

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.

andreaskern avatar andreaskern commented on July 20, 2024 5

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.

asbjornenge avatar asbjornenge commented on July 20, 2024 4

I would suggest implementing naivechain-pow as a separate module that naivechain can use or not 😄

from naivechain.

japesh avatar japesh commented on July 20, 2024 2

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.

asbjornenge avatar asbjornenge commented on July 20, 2024 1

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.

lhartikk avatar lhartikk commented on July 20, 2024 1

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.

antony avatar antony commented on July 20, 2024

@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.

andreaskern avatar andreaskern commented on July 20, 2024

@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.

antony avatar antony commented on July 20, 2024

@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.

antony avatar antony commented on July 20, 2024

Works for me - If you don't mind linking my version as a 'class based' version or something, that would be great :)

from naivechain.

Sowmayjain avatar Sowmayjain commented on July 20, 2024

Can someone provide the link to the repo with added functionality in Naive Chain?

from naivechain.

japesh avatar japesh commented on July 20, 2024

got it @lhartikk

from naivechain.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.