Node atomicity rehabilitated
This commit is contained in:
parent
bd9070ae44
commit
1047a1a487
@ -55,6 +55,20 @@ class Nonce(SessionBase):
|
||||
conn.execute("UPDATE nonce set nonce = {} WHERE address_hex = '{}'".format(nonce, address))
|
||||
|
||||
|
||||
@staticmethod
|
||||
def __inc(conn, address):
|
||||
#conn.execute("UPDATE nonce set nonce = nonce + 1 WHERE address_hex = '{}'".format(address))
|
||||
q = conn.query(Nonce)
|
||||
q = q.filter(Nonce.address_hex==address)
|
||||
q = q.with_for_update()
|
||||
o = q.first()
|
||||
nonce = o.nonce
|
||||
o.nonce += 1
|
||||
conn.add(o)
|
||||
conn.flush()
|
||||
return nonce
|
||||
|
||||
|
||||
@staticmethod
|
||||
def __init(conn, address, nonce):
|
||||
conn.execute("INSERT INTO nonce (nonce, address_hex) VALUES ({}, '{}')".format(nonce, address))
|
||||
@ -107,7 +121,7 @@ class Nonce(SessionBase):
|
||||
#Nonce.__init(conn, address, nonce)
|
||||
Nonce.__init(session, address, nonce)
|
||||
#Nonce.__set(conn, address, nonce+1)
|
||||
Nonce.__set(session, address, nonce + 1)
|
||||
nonce = Nonce.__inc(session, address)
|
||||
#if Nonce.transactional:
|
||||
#conn.execute('COMMIT')
|
||||
# logg.debug('unlocking nonce table for address {}'.format(address))
|
||||
|
@ -48,7 +48,7 @@ def test_nonce_reserve(
|
||||
uu = uuid.uuid4()
|
||||
nonce = NonceReservation.next(eth_empty_accounts[0], str(uu), session=init_database)
|
||||
init_database.commit()
|
||||
assert nonce == 42
|
||||
assert nonce == (str(uu), 42)
|
||||
|
||||
q = init_database.query(Nonce)
|
||||
q = q.filter(Nonce.address_hex==eth_empty_accounts[0])
|
||||
@ -57,7 +57,7 @@ def test_nonce_reserve(
|
||||
|
||||
nonce = NonceReservation.release(eth_empty_accounts[0], str(uu))
|
||||
init_database.commit()
|
||||
assert nonce == 42
|
||||
assert nonce == (str(uu), 42)
|
||||
|
||||
q = init_database.query(NonceReservation)
|
||||
q = q.filter(NonceReservation.key==str(uu))
|
||||
|
Loading…
Reference in New Issue
Block a user