Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion-0001 : Ordering in Parallel TX Processing #177

Open
StuartFarmer opened this issue Aug 2, 2018 · 1 comment
Open

Discussion-0001 : Ordering in Parallel TX Processing #177

StuartFarmer opened this issue Aug 2, 2018 · 1 comment
Assignees

Comments

@StuartFarmer
Copy link
Contributor

Assume the following:

token.balance_of('stu') = 10

def transfer(from, to, amount):
    from_balance = get_balance_row(from)
    to_balance = get_balance_row(to)

    if from_balance >= amount:
        write_balance_row(to, to_balance + amount)
        write_balance_row(from, from_balance - amount)
rows affected in order:
[
    (READ, from),
    (READ, to),
    (WRITE, to),
    (WRITE, from)
]

Subtree block from MN-Africa:

transfer('raghu', 'stu', 1)

[
    (READ, 'raghu'),
    (READ, 'stu'),
    (WRITE, 'stu'),
    (WRITE, 'raghu')
]

Subtree block from MN-Asia:

transfer('stu', 'davis', 1)

[
    (READ, 'stu'),
    (READ, 'davis'),
    (WRITE, 'davis'),
    (WRITE, 'stu')
]

Subtree block from MN-America:

def funky_town(from, to_1, to_2, to_3):
    from_balance = get_balance_row(from)

    if from_balance < 10:
        transfer(from, to_1)
    elif from_balance > 10:
        transfer(from, to_2)
    else: # balance == 10
        transfer(from, to_3)

funky_town('stuart', 'raghu', 'davis', 'falcon'

Delegate Africa gets subtrees in order:

transfer('raghu', 'stu', 10)
transfer('stu', 'davis', 1)
funky_town('stuart', 'raghu', 'davis', 'falcon'

rows affected:

[
    (READ, 'raghu'),
    (READ, 'stu'),
    (WRITE, 'stu'),
    (WRITE, 'raghu')
],
[
    (READ, 'stu'),
    (READ, 'davis'),
    (WRITE, 'davis'),
    (WRITE, 'stu')
],
[ # funky_town
    (READ, 'stu'), # balance == 19, transfer to falcon
    
    (READ, 'stu'),
    (READ, 'raghu'),
    (WRITE, 'raghu'),
    (WRITE, 'stu')
]

Delegate Asia gets subtrees in order:

transfer('stu', 'davis', 1)
funky_town('stuart', 'raghu', 'davis', 'falcon'
transfer('raghu', 'stu', 10)

rows affected:
[
    (READ, 'stu'),
    (READ, 'davis'),
    (WRITE, 'davis'),
    (WRITE, 'stu')
],
[ # funky_town
    (READ, 'stu'), # balance == 9, transfer to davis
    
    (READ, 'stu'),
    (READ, 'davis'),
    (WRITE, 'davis'),
    (WRITE, 'stu')
],
[
    (READ, 'raghu'),
    (READ, 'stu'),
    (WRITE, 'stu'),
    (WRITE, 'raghu')
]

Delegate America gets subtrees in order:

funky_town('stuart', 'raghu', 'davis', 'falcon'
transfer('raghu', 'stu', 1)
transfer('stu', 'davis', 1)

rows affected:
[ # funky_town
    (READ, 'stu'), # balance == 10, transfer to falcon
    
    (READ, 'stu'),
    (READ, 'falcon'),
    (WRITE, 'falcon'),
    (WRITE, 'stu')
],
[
    (READ, 'raghu'),
    (READ, 'stu'),
    (WRITE, 'stu'),
    (WRITE, 'raghu')
],
[
    (READ, 'stu'),
    (READ, 'davis'),
    (WRITE, 'davis'),
    (WRITE, 'stu')
]

Under this system, by describing smart contracts as READs and WRITEs, we can find the collisions and rerun them.

@JeffWScott
Copy link
Contributor

JeffWScott commented Aug 2, 2018

Unless I'm not understanding, I think you mixed up in your funkytown results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants