Live data from Hacker News

Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell

github.com

21–30 of 73 posts

Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell

#21

... had this been written in a language less esoteric than Haskell, it would've been even better for the rest of us :)

I think it's too bad we don't have module interoperability. There's never going to be just one programming language. The situation on the JVM -- where Scala, Java and Kotlin can use one another's modules -- is a positive example. Clang modules and Swift's auto-magic import of them is another.

I'm pretty uninformed about libffi but can it help with kind of module interoperability? I've used it to get Ruby to call C functions. I would guess that it could be used for other dynamic languages to call compiled functions such as JS to Haskell like the OP seems to be desiring. Is this true?

Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell

#22
post #20

Earlier quoted context omitted.

A very simple proof of work is adding a token to the data before hashing: sha256(token + data + previous hash) i.e. (for simplicity, previous hash = "") sha256("1" + "example" + PreviousHash) -> ee73735c2355bc4d63319a6638e356ef42d0d56746317c99f52d3e7ac71cbf52 sha256("2" + "example" + PreviousHash) -> 6236cd42286c74a1683eaf394b3b2f40a3a52479e1a3d7e732175fcdfa49b931 ... sha256("10" + "example" + PreviousHash) -> 346fea…

Note that "the first X characters" is kind of misleading, because it is usually more fine grained. It is better (and IMHO even simpler!) to think of the hash as a large integer, not a string. Then you want that integer to be smaller than a certain value. With strings, you can only say: "00123" shall start with "00", while wih integers, you would say: 00123 shall be smaller than 300. (To be that fine grained with stri…

I agree with the gist, but note that even with strings, "00122" is less than "00200" :)

Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell

#23

Earlier quoted context omitted.

Correct, the goal for this was as minimal as possible. However, if I (or anyone wanting to contribute) can come up with a very compact way to implement that, we could definitely add it!

A very simple proof of work is adding a token to the data before hashing: sha256(token + data + previous hash) i.e. (for simplicity, previous hash = "") sha256("1" + "example" + PreviousHash) -> ee73735c2355bc4d63319a6638e356ef42d0d56746317c99f52d3e7ac71cbf52 sha256("2" + "example" + PreviousHash) -> 6236cd42286c74a1683eaf394b3b2f40a3a52479e1a3d7e732175fcdfa49b931 ... sha256("10" + "example" + PreviousHash) -> 346fea…

[deleted]

Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell

#24
post #20

Earlier quoted context omitted.

Note that "the first X characters" is kind of misleading, because it is usually more fine grained. It is better (and IMHO even simpler!) to think of the hash as a large integer, not a string. Then you want that integer to be smaller than a certain value. With strings, you can only say: "00123" shall start with "00", while wih integers, you would say: 00123 shall be smaller than 300. (To be that fine grained with stri…

I agree with the gist, but note that even with strings, "00122" is less than "00200" :)

Oh, you are right! However, my point still stands that this is not about prefixes, but about a less-than comparison.

Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell

#25

Earlier quoted context omitted.

I think it's too bad we don't have module interoperability. There's never going to be just one programming language. The situation on the JVM -- where Scala, Java and Kotlin can use one another's modules -- is a positive example. Clang modules and Swift's auto-magic import of them is another.

I'm pretty uninformed about libffi but can it help with kind of module interoperability? I've used it to get Ruby to call C functions. I would guess that it could be used for other dynamic languages to call compiled functions such as JS to Haskell like the OP seems to be desiring. Is this true?

Most languages have some degree of interoperability with C, but that means losing all of the nice features of whatever languages you're using, even if they're implemented on both ends.

Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell

#26

Earlier quoted context omitted.

I think it's too bad we don't have module interoperability. There's never going to be just one programming language. The situation on the JVM -- where Scala, Java and Kotlin can use one another's modules -- is a positive example. Clang modules and Swift's auto-magic import of them is another.

I'm pretty uninformed about libffi but can it help with kind of module interoperability? I've used it to get Ruby to call C functions. I would guess that it could be used for other dynamic languages to call compiled functions such as JS to Haskell like the OP seems to be desiring. Is this true?

The hardest part of combining two languages through a foreign function interface (eg Ruby/C using libffi) is making their garbage collectors work together. You basically have to either use a single garbage collector across the language boundary, like the family of languages implemented on the JVM do, or require one or both of the languages to implement GC-less memory management, like in the Ruby/C case.

Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell

#28
post #20

Earlier quoted context omitted.

A very simple proof of work is adding a token to the data before hashing: sha256(token + data + previous hash) i.e. (for simplicity, previous hash = "") sha256("1" + "example" + PreviousHash) -> ee73735c2355bc4d63319a6638e356ef42d0d56746317c99f52d3e7ac71cbf52 sha256("2" + "example" + PreviousHash) -> 6236cd42286c74a1683eaf394b3b2f40a3a52479e1a3d7e732175fcdfa49b931 ... sha256("10" + "example" + PreviousHash) -> 346fea…

Note that "the first X characters" is kind of misleading, because it is usually more fine grained. It is better (and IMHO even simpler!) to think of the hash as a large integer, not a string. Then you want that integer to be smaller than a certain value. With strings, you can only say: "00123" shall start with "00", while wih integers, you would say: 00123 shall be smaller than 300. (To be that fine grained with stri…

You can implement 0 prefix checking pretty easily in bitstrings:

    0 == hash >> (hash_length - prefix_length)
Or, alternatively:

    !(hash & prefix_mask)
where `prefix_mask` is 1111..000, with `prefix_length` number of 1s.

I think that working in terms of bitstrings generated by the hash gives more context to why those integers are chosen (that they represent a certain portion of the space of possible answers), but it's also a matter of taste/background.

Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell

#29
Nicely done. It reads like Ikea instructions. I didn't really know how blockchain worked until I read this code. If this was written as a teaching tool or a portfolio piece or even an art project, then I say its a big success.

One question:

    getBlockChain :: (SpockState m ~ BlockChainState, MonadIO m, HasSpock m) => m [Block]
What does the squiggle mean?

Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell

#30
post #29

Nicely done. It reads like Ikea instructions. I didn't really know how blockchain worked until I read this code. If this was written as a teaching tool or a portfolio piece or even an art project, then I say its a big success. One question: getBlockChain :: (SpockState m ~ BlockChainState, MonadIO m, HasSpock m) => m [Block] What does the squiggle mean?

It is an equality assertion: https://downloads.haskell.org/~ghc/7.6.1/docs/html/users_gui...
Post reply on HN