EOS - Developer’s Log Stardate 201707.3

in #eos7 years ago (edited)

Today I met with the team to discuss the challenges of making smart contracts both easy to develop and easy to execute in parallel. If you are familiar with the challenges associated with parallel execution then you know the general rule that all data must be owned by a single thread. In terms of blockchains, that means all accounts need to own their data. Owning data means that no other thread of execution may read or write the data except by asynchronous message passing.

The Current Balance Problem

Suppose you want to read the current balance of another contract, something that seems like it should be trivial. If the balance is “owned” by another account, say the currency contract, then your contract cannot “read it”. You could attempt to query it by asynchronous communication, but that would be liking sending your bank a letter asking for a balance update and waiting for a response in the mail. By the time you get the response (if you get a response), the balance may already be out of date.

Fortunately, EOS makes it easy for one account to monitor all deposits and withdraws. In this case the reader contract would maintain its own logic duplicating the balance calculation and storage of the currency contract. This approach is also error prone because any small difference in behavior could result in your balance calculation differing from the currency contract.

Another alternative is to use an oracle that will notify your contract of the balance while simultaneously delivering a message to the currency contract. The currency contract will reject the transaction if the oracle lied, therefore, your contact can trust the balance reported. Once again this only lets you know the balance for the split second your transaction is applied and creates a new problem that your transaction can be invalidated if other user actions are modifying your balance at the same instance.

The underlying challenge here is that the balance data is owned by a different thread and therefore it cannot be reliably read and used when needed.

Redefining the Problem

Under the above model, all data is owned by a single account and its code. This makes each account like its own blockchain and communication among accounts tricky. Fortunately, GPU developers have used another parallelization strategy: SMID - single instruction multiple data. Stated more generally, a GPU executes the exact same code over many independent instances of the data. Every pixel and/or vertex is modified by the same set of instructions.

Imagine for a moment that every account balance was represented as pixel in an image. Imagine that a smart contract was defined like a shader. A pixel shader can only write to a single pixel, but it can read from any number of other read-only sources.

Under this model a currency contract is not defined as code that operates on a mapping of account name to balance, but instead as code that operates on a single balance belonging to a single account. The currency contract would not be able to read other accounts balances, but it would know with certainty that all accounts were running the same code.

What would such a contract look like?

void apply_simplecoin_transfer() {
   static Transfer message;
   static uint64_t balance = 0;
   load( thisContract(), “balance”, balance );
   
   readMessage( message  );
   requireNotify( {message.from, message.to} );
   
   if( thisAccount() == message.to ) {
      balance += message.amount;
   } else if ( thisAccount() == message.from ) {
      assert( message.amount < balance, "insufficient funds" )
      balance -= message.amount;
   }
   
   if( balance ) store( “balance”, balance );
   else remove( “balance”, balance );
}

Notice there are a few subtle differences:

  1. The apply method only modifies a single balance
  2. The behavior of the contract depends upon the value of thisAccount()
  3. The load() method takes an extra parameter specifying the current contract
  4. The store() and remove() methods always use the “balance” key rather than an account key.

If we assume all accounts run this exact same code on their private data, we can still guarantee that there are no double spends. This is possible because every account requires both the sender and receiver to be notified of the message or the message will be rejected (both parties can be notified in parallel).

The receiver knows that the sender must have sufficient funds or the receiver will reject the message; therefore, the receiver can safely increment its own balance. Likewise, the sender knows the receiver will increment his balance so he decrements his own.

What does this give us?

Well now that we have this design pattern we have separated “code” from “data” in terms of parallelization. A single account can now run code provided by other accounts and the code provided by other accounts can now read all data belonging to an account.

Suppose you wanted to build a social media platform where vote weight is proportional to current balance. This is something that requires the social media account to have the ability to read your balance and modify someone else’s post vote totals. In the ideal world it would be nice for @alice to vote for @bob while @sam is voting for @bill. This could be achieved as follows:

void apply_social_vote() {
   readMessage( vote );
   if( vote.for == thisContract() ) {
      load( thisContract(), vote.postid, post );
      post.totalvotes += vote.weight;
      store( vote.postid, post );
   } 
   
   if( vote.voter == thisAccount() ) {
      static uint64_t balance = 0;
      load( "simplecoin", "balance", balance );
      assert( balance >= vote.weight, “insufficient balance for vote weight” );
   }
}

In this case the contract code does two different things depending upon which data it is operating on. If it is operating on the receiver of the vote, then it increments the total votes. If it is operating on the sender, then it simply verifies the vote.weight <= the balance.

It should be noted that the vote receiver is still unable to read the vote giver’s balance. However, in this model two votes can be processed by 4 different accounts in parallel and it will work so long as the voter reports a vote weight that is accurate.

While it may not be possible to read someone else’s balance while modifying your state, it is possible to read your own balance from the “simplecoin” contract from within the “social” contract.

What is everything so complicated?

As programmers we would love to read whatever we want, whenever we want, and let the computer figure things out. The naive approach is to simply put locks around data. If two people “happen” to read the data at the same time, then one will wait for the other. Unfortunately for blockchain developers, the outcome of these race conditions is not deterministic and therefore could break consensus.

A New Hope

There is a way to allow one account to read another account’s balance; the transaction can declare that it requires read access. The blockchain’s transaction scheduler can then ensure that no one that requires write access will execute code at the same time. Using the old approach to simplecoin (one contract owning all the data), this would create a lot of congestion around that contract as everyone needing to read would be blocking those who want to write and everyone would be bottlenecked by a single contract.

However, using the new approach to simplecoin, the probability that two transactions need to access the same account data at the same time is much lower. This will reduce lock contention and maximize throughput.

Conclusion

Parallelism is hard, especially when you need things to be deterministic while accessing shared data. Fortunately, there are solutions available and design patterns proven by those who design GPUs and computer graphics algorithms.

Disclaimer Nothing in this blog post should be construed to imply any particular feature or functionality of the EOS.IO software. All software designs subject to change as necessary.

Sort:  

My apologies, key board shortcuts ended up submitting this before I was done and I had not yet declined payouts.

And why should you not be allowed to be upvoted just like the rest of us? I think your posts are very valuable and we are a legion who thinks the same. Take Our Upvotes! Never Decline!

Because payouts are declined it is obviously unecessary. It is actually helpful to the community. It would be better to say " thank you for declining payouts"

@fyrstikken, self-upvoting might be part of the reasons why a new platform could overtake Steemit > https://steemit.com/steemit/@blockrush/is-wildspark-the-steemit-killer-blockrush

You know what to put in the next update so

Yeah U Are Right Offcoure He Know What To Put In The Next Update so

battletoads

Please don't apologize for beeing awesome :-)

Like a mother apologizing for giving birth. Come on now, Dan! Accept and reap your rewards!

I, personally, knowing that you don't even need it, feel great giving you a 100% upvote. You've navigated the majority of this into existence, and that's something to be proud of. I understand being humble, but you have the right to be proud. You've emancipated and liberated countless human beings with your work. Take time to reflect on that. If you have that ability and execute it, you damn well better believe you have the right to take pride in it all.

Dude, you're spearheading some seriously revolutionary shit. Just saying. It's (well, was) the 4th of July! Independence! Emancipation! Sovereignty! FREEDOM! That is what you are doing. Reward the shit out of this post as hard as you can. You and your Dad are straight up on George Washington levels in my eyes.

The platforms that now exist now give myself, my family, my friends, and those that I care about, and society at large a one way ticket to life, liberty, and the pursuit of happiness. And on a cryptographically secure route! We live in some wild times . . . This is pioneer territory . . .

I guess that I'm just writing to say that I don't think that you should apologize for anything. You all have bestowed upon the Earth something fierce! A tool that two human beings can utilize to facilitate the transfer of value as they see fit. True liberation. Take pride in it, and sleep well.

HAPPY (late) 4TH OF JULYYYY!!!

</drunken4thofJulyRant>

Thank you Dan for keeping us updated.

Congrats by the way for the EOS initial coin offer.
Follow me @Yehey

Go get yourself i nive Dinner @Dan, you've earned it ;)

I had the same thing a few days ago and it was annoying. That's why i normally leave the tags empty until i'm absolutely ready to publish...

i have fallowed you .. and i will vote u
fallow me please and tell me when u do it
tnx

🐳 WhaleBoT says: @ndnd92, warning: vote/follow begging is shunned upon, watch out or I'll EAT YA! 🙁

Mr @Dan, your hard work at Steemit might not last if Steemit does not live to its role in maintaining and development Steemit.
With your attention divided between Steemit and EOS, Steemit is needs Steemit Inc now more than ever. There is a new Steemit killer arising > https://steemit.com/steemit/@blockrush/is-wildspark-the-steemit-killer-blockrush

No need to apologize. Total newbie minnow here, but from what I've seen, Steemit is a win-win environment. The stronger you are, the stronger the community is.

So, enjoy!

Hi thanks for this update, I have been on the edge of whether to invest or not for a while. Now I see it on the exchanges I am a bit confused, is it most probably going to be cheaper if I buy from the ICO or off the exchange or is it anybodys guess? Thanks.

from the EOS.IO website I gather that EOS does not support/encourage any transaction made on exchanges. So I would not risk it (i.e. poloniex, kraken etc..)

Thanks yeh, I've just read Jerry Banfield's post about investing in ICO's and I'm going off them now! Although saying that, everytime a new exciting one pops up I'm like I must have this one! Then the rush dies down again until the next time!

Thank you for the update - great to see this level of communication from a lead dev!

What language do i need to become a eos developer? Have been looking for a learning project to get me back into programming.

Their github repo is mainly C++14. So knowing C++ should be sufficient I think.

When talking about programming does make a headache. But we must understand this.

Even Word press is also ok for beginner or can go with C++ , .net platform etc...

excellent question ,, want an answer too

lots of year of practice with C++ , C and block-chain technology

Cool, will be getting some tonight, glad they have it in Kraken with a few pairs (ETH, BTC, USD, EUR)

Thanks @dan !!

It's always nice to get an update about a project that many are investing in, and knowing that the minds behind said projects are actually truly interested in what they're doing.

Much luck with the new challenges, but if anyone is suited for solving them it's none other than you, Dan.

Cheers.

If this is a ether killer, would it be wise to dump your ether reserves if you are going to hold eos for the long term? Seems counter productive to invest in something thats suppose to be killed by something else your invested in. Its like investing in batamax and vhs at the same time

I look at it as hedging my bets. I love Ethereum and am heavily invested in it, but EOS shows a lot of promise and could solve some of Ethereum's thornier issues. However Ethereum has first mover advantage much like Bitcoin does. I have no idea which smart contracts platform will ultimately win out in the end. So I'm buying both. And I also bought into the Tezos ICO. I think there's a very good chance all 3 investments will be highly profitable. Why own one slice of the smart contract pie when you can stick your fingers in multiple pieces?

It's all depending on your tolerance for risk. For me I just can't handle it. I bought into EOS and there's been so many swings, I can't sleep at night. I don't have much cash right now, so it makes me pretty nervous when I have 30 grand out there. I tried day trading when I should have just held onto it and missed out huge. Sold a bunch at 6 then bought a little bit back at 6 thinking it was on its way up again and it plummeted the last day and a half. Only time will tell.

I have a pretty high tolerance for risk as I try to look at EOS with a long-term perspective. The real value won't come for at least a year anyway after the actual EOS blockchain launches. What we have right now is 100% speculation, pure & simple. 30 grand is a lot; if you're down now, I would just forget about it for a while and check back in a few months to see how things are going.

I screwed up round 0 pretty bad. Bought a ton then sold most of it when trading first started, happy with a roughly 1.5x return and thinking the price would immediately crash. Instead it went up 6x and I was just kicking myself for not holding. Now I've looking to re-buy if we go lower down, or maybe start cost averaging my way back in if we stay at this level for a while.

Sorry to hear that. I wish I just bought some than left for a few days. Sadly my ocd wont let me just forget about it. I am always buying and selling. Have most of my money sitting in ether right now. Bought about 2000 units of eos at around $2.55 a unit. I guess it is a small enough sum where I can just forget about it for 6 months. The challenge is, if it takes the same path that steem did, it will be a long time before it goes back up to $6. Steem has never made its way back up to $3 and its been a year or more.Nevertheless, seeing that a lot of people probably ended up paying $6 plus for their eos, I am pretty sure those people will be holding for the long term

What would be a good rebuy point? You would think anyone actually still left holding bags of eos paid over $3 so anyone that is still in it has no incentive to sell

Now is actually a pretty good rebuy point as it seems to be building a base at this level. I bought back 1000 EOS yesterday when the price briefly dipped below 0.01 ETH/EOS, and will buy more if it continues to hover around the current price.

Bought about 2000 units of eos at around $2.55 a unit.

That's looking like a pretty smart entry point as long as you're willing to let it sit and not looking for a quick flip. If it does go down further from here, then I'll be looking to make a series of small buys, cost averaging my way in and lowering my overall cost basis until we hit bottom. If the price hits the round 0 ICO price or below, I'll pile in with 20 or 30 more ETH.

In the long term, my target is to accumulate 10,000 EOS by the end of the year long ICO. For something like this where it's really hard to predict price swings, I think cost averaging is King. That's basically how I accumulated all my Steem Power, with lots of small buys while the Steem price was falling. And now Steem has turned into my 2nd best investment ever after Ethereum. Happily, the EOS ICO structure is a wet dream for anyone wanting to cost average, as you can just spread your ETH out over time, fire & forget and not worry about the emotional component of trading on the market. So participating in the ICO rounds with small amounts + timed larger buys on the market when price dips = potential winning strategy.

Awesome that's what I plan to do . I started with about 10,000 EOS, sadly now I am only down to 2000 and am sitting on a bunch of ETH I bought at a high point - about $256 per unit. I never got the chance to buy in lower because it took me 2 months to get trading at a large volume amount. Nevertheless thanks for the advice. I will be holding for the year and hopefully this will turn into another ether. I just have to stop looking at the prices on a daily basis and maybe only look once a week lol.

But in fact - what will happen with all the purchased etherium? Will they throw him out for a cheap sale?

I doubt they will dump all at once. That wouldn't make sense; in order to get the most money the EOS team will probably sell gradually so as not to move the market too much.

Thanks for the reponse by the way.

Keep up the great work!

Nice post mate. It's very good to see some techie here.

Much coding will produce much pine sol, Dan unit. Much pin sol. Heterogenous computing is agreeable.

may-the-source-be-with-you.jpg

Much gratitude for free pinesol upvote from @jamesc1. Much pine sol to you!

Coin Marketplace

STEEM 0.33
TRX 0.11
JST 0.034
BTC 66438.74
ETH 3268.32
USDT 1.00
SBD 4.39