mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle...

92
mLSM: Making Authenticated Storage Faster in Ethereum Pandian Raju 1 , Soujanya Ponnapalli 1 , Evan Kaminsky 1 , Gilad Oved 1 , Zachary Keener 1 Vijay Chidambaram 1,2 , Ittai Abraham 2 1 The University of Texas at Austin; 2 VMware Research 1

Transcript of mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle...

Page 1: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

mLSM: Making Authenticated Storage Faster in Ethereum

Pandian Raju1, Soujanya Ponnapalli1, Evan Kaminsky1, Gilad Oved1, Zachary Keener1

Vijay Chidambaram1,2, Ittai Abraham2

1The University of Texas at Austin;2VMware Research

1

Page 2: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Ethereum

• Distributed software platform• Cryptocurrency applications• Key-value store• Accounts : Balances• Trustless Decentralized setting

2

Page 3: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Ethereum – Distributed Decentralized System

3

B1 B2 B3

Node1

Node2

Node4Node3

Node4

B4

Page 4: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Need for Authenticated Storage

4

User A, Balance: $500

User C, Balance: $500000

A

User B, Balance: $5000

User B, Balance: $5000

User A, Balance: $0

User C, Balance: $0

Balance (A) ?

Balance : $0

Balance : $0

Page 5: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authenticated Storage

• Users can verify the value returned by a node• Each read is returned with the value and a proof

5

User A, Balance: $500

User C, Balance: $500000

A

User B, Balance: $5000

Balance (A) ?

[ $500, PROOF ]

Page 6: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication Techniques in Ethereum

• Ethereum authenticated storage suffer from high IO Amplification• 64x in the worst case• IO Amplification• Ratio of the amount of IO to the amount of user data

6

ClientUser data : 10 GB

Server

User data : 10 GBTotal write IO : 500 GB

Write Amplification : 50

Page 7: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Why is IO Amplification bad?

• Reduces the write throughput• Directly impact the life of Flash devices• Flash devices wear out after limited write cycles

(Intel SSD DC P4600 can last ~5 years assuming ~5 TB write per day)

For the same SSD life expectancy, with 65x IO Amplification, instead of 5TB of data we can now only write ~75 GB of user data per day

7

Page 8: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

How to design an authenticated storage system that minimizes IO amplification?

Merkelized LSM• Maintains multiple mutually independent binary merkle trees• Decouples lookup from authentication• Minimizes IO Amplification

8

Page 9: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Outline

• Authentication in Ethereum• Why caching doesn’t work?• Merkelized LSM

9

Page 10: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authenticated Storage in Ethereum

10

Page 11: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Merkle Trees – Fundamental building blocks

11

K1 : v1 K2 : v2 K3 : v3 K4 : v4

H(v1-2) H(v3-4)

H(v1-4)

K4 : V4’

H(v3-4’)

H(v1-4’)

With a constant sized root hash,we can authenticate all thekey-value pairs

Root hash is publicly available to all clients

Page 12: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Client queries for value of key k4• Server replies with the value

12

K1 : v1 K2 : v2 K3 : v3

P1 P2

Root

K4 : v4K4 : v4

Page 13: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Client queries for value of key k4• Server replies with the value• Along with a Merkle Proof

13

K1 : v1 K2 : v2 K3 : v3 K4 : v4

P1 P2

Root

K4 : v4K3 : v3

P1

Root

Page 14: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Client queries for value of key k4• Server replies with the value• Along with a Merkle Proof

14

K1 : v1 K2 : v2 K3 : v3 K4 : v4

P1 P2

Root

K4 : v4

k3 : v3Root P1 K4 : v4Response :

Page 15: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Client verifies the value by calculating the root hash from the value and Merkle proof

15

K1 : v1 K2 : v2 K3 : v3 K4 : v4

P1 P2

Root

K4 : v4

k3 : v3Root P1 K4 : v4Response :

Page 16: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

16

K1 : v1 K2 : v2 K3 : v3 K4 : v4

P1 P2

Root

K4 : v4

• Client verifies the value by calculating the root hash from the value and Merkle proof

K3 : v3Root P1 K4 : v4Response :

Page 17: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

17

K1 : v1 K2 : v2

P1 P2

Root

• Client verifies the value by calculating the root hash from the value and Merkle proof

Root P1Response : P2

K3 : v3 K4 : v4

P2

Page 18: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Client queries for value of key k4• Server replies with value and a

Merkle Proof

18

K1 : v1 K2 : v2 K3 : v3

P1 P2

Root

K4 : v4

Root P1Response : P2

Page 19: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Client queries for value of key k4• Server replies with value and a

Merkle Proof

19

K1 : v1 K2 : v2 K3 : v3

P1 P2

Root

K4 : v4

Root P1Response : P2

P1

Page 20: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Client verifies the value by calculating the root hash from the value and Merkle proof

20

K1 : v1 K2 : v2 K3 : v3 K4 : v4

RootResponse : Root

Root

P1 P2

Page 21: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Client verifies the value by calculating the root hash from the value and Merkle proof

21

K1 : v1 K2 : v2 K3 : v3

P1 P2

Root

K4 : v4

RootResponse : Root ?

Page 22: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Server can no longer lie about the data

22

K1 : v1 K2 : v2 K3 : v3 K4 : v4

P1 P2

Root

K4 : v4

k3 : v3Root P1 K4 : v4’Response :

Page 23: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

23

K1 : v1 K2 : v2 K3 : v3 K4 : v4

P1 P2

Root

K4 : v4

• Server can no longer lie about the value

K3 : v3Root P1 K4 : v4’Response :

Page 24: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

24

K1 : v1 K2 : v2

P1 P2

Root

• Client verifies the value by calculating the root hash from the value and Merkle proof

Root P1Response : P2’

K3 : v3 K4 : v4

P2

Page 25: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Client queries for value of key k4• Server replies with value and a

Merkle Proof

25

K1 : v1 K2 : v2 K3 : v3

P1 P2

Root

K4 : v4

Root P1Response : P2’

Page 26: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Client queries for value of key k4• Server replies with value and a

Merkle Proof

26

K1 : v1 K2 : v2 K3 : v3

P1 P2

Root

K4 : v4

Root P1Response : P2’

P1

Page 27: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Client verifies the value by calculating the root hash from the value and Merkle proof

27

K1 : v1 K2 : v2 K3 : v3 K4 : v4

RootResponse : Root’

Root

P1 P2

Page 28: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication using Merkle Trees

• Server cannot lie about the value

28

K1 : v1 K2 : v2 K3 : v3

P1 P2

Root

K4 : v4

RootResponse : Root’ ?

Page 29: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Merkle Patricia Trie

• Similar to Merkle trees • Lookup based on the key structure• Considering 4 bit hex key-value pairs:• 0x20 – V1• 0x2f – V2• 0x51 – V3• 0x5e – V4

29

2

Root Hash

P1

5

f 1

Branching: 0 - f

V1

P2

0

V2 V3

e

V4

Page 30: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authenticated Storage in Ethereum

• Trie is flattened and stored as key value pairs• For every leaf node V, we store

[Hash(V) -> V]• For every parent node P, we have an

[Hash(P) -> [ … ]].

30

2

Root Hash

P1

5

f 1

Branching: 0 - f

V1

P2

0

V2 V3

e

V4

Page 31: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authenticated Storage in Ethereum

31

2

Root Hash

P1

5

f 1

Branching: 0 - f

V1

P2

0

V2 V3

e

V4

KEY VALUE

Page 32: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authenticated Storage in Ethereum

32

2

Root Hash

P1

5

f 1

Branching: 0 - f

V1

P2

0

V2 V3

e

V4

KEY VALUE

Hash (V1) V1

Hash (V2) V2

Hash (V3) V3

Hash (V4) V4

Page 33: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authenticated Storage in Ethereum

33

2

Root Hash

P1

5

f 1

Branching: 0 - f

V1

P2

0

V2 V3

e

V4

KEY VALUE

Hash (V1) V1

Hash (V2) V2

Hash (V3) V2

Hash (V4) V3

Hash (P1) Hash (V1),Hash (V2)

Hash (P2) Hash (V3),Hash (V4)

Page 34: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authenticated Storage in Ethereum

34

2

Root Hash

P1

5

f 1

Branching: 0 - f

V1

P2

0

V2 V3

e

V4

KEY VALUE

Hash (V1) V1

Hash (V2) V2

Hash (V3) V3

Hash (V4) V4

Hash (P1) Hash (V1),Hash (V2)

Hash (P2) Hash (V3),Hash (V4)

Hash (RH) Hash (P1),Hash (P2)

Page 35: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Read Amplification in Ethereum

35

2

Root Hash

P1

5

f 1

Branching: 0 - f

V1

P2

0

V2 V3

e

V4

KEY VALUE

Hash (V1) V1

Hash (V2) V2

Hash (V3) V3

Hash (V4) V4

Hash (P1) Hash (V1), Hash (V2)

Hash (P2) Hash (V3), Hash (V4)

Hash (RH) Hash (P1), Hash (P2)

Get (0x2f)

Page 36: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Read Amplification in Ethereum

36

2

Root Hash

P1

5

f 1

Branching: 0 - f

V1

P2

0

V2 V3

e

V4

Get (0x2f)

Get (Hash(RH))KEY VALUE

Hash (V1) V1

Hash (V2) V2

Hash (V3) V3

Hash (V4) V4

Hash (P1) Hash (V1), Hash (V2)

Hash (P2) Hash (V3), Hash (V4)

Hash (RH) Hash (P1), Hash (P2)

Page 37: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Read Amplification in Ethereum

37

2

Root Hash

P1

5

f 1

Branching: 0 - f

V1

P2

0

V2 V3

e

V4

Get (0x2f)Get (Hash(P1))

KEY VALUE

Hash (V1) V1

Hash (V2) V2

Hash (V3) V3

Hash (V4) V4

Hash (P1) Hash (V1), Hash (V2)

Hash (P2) Hash (V3), Hash (V4)

Hash (RH) Hash (P1), Hash (P2)

Page 38: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Read Amplification in Ethereum

38

2

Root Hash

P1

5

f 1

Branching: 0 - f

V1

P2

0

V2 V3

e

V4

Get (0x2f)Get (Hash(V2))

KEY VALUE

Hash (V1) V1

Hash (V2) V2

Hash (V3) V3

Hash (V4) V4

Hash (P1) Hash (V1), Hash (V2)

Hash (P2) Hash (V3), Hash (V4)

Hash (RH) Hash (P1), Hash (P2)

Page 39: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Write Amplification in Ethereum

39

2

Root Hash

P1

5

f 1

Branching: 0 - f

V1

P2

0

V5 V3

e

V4

Update (0x2f, 5)Update (Hash(V5), V5)

KEY VALUE

Hash (V1) V1

Hash (V5) V5

Hash (V3) V3

Hash (V4) V4

Hash (P1) Hash (V1), Hash (V2)

Hash (P2) Hash (V3), Hash (V4)

Hash (RH) Hash (P1), Hash (P2)

Page 40: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Write Amplification in Ethereum

40

2

Root Hash

P1’

5

f 1

Branching: 0 - f

V1

P2

0

V5 V3

e

V4

Put (0x2f, 5)Update (Hash (P1’))

KEY VALUE

Hash (V1) V1

Hash (V5) V5

Hash (V3) V3

Hash (V4) V4

Hash (P1’) Hash (V1), Hash (V2)

Hash (P2) Hash (V3), Hash (V4)

Hash (RH) Hash (P1), Hash (P2)

Page 41: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Write Amplification in Ethereum

41

2

Root Hash’

P1’

5

f 1

Branching: 0 - f

1

Hash 3 - 4

0

5 3

e

4

Put (0x2f, 5)Update (RH’)

KEY VALUE

Hash (V1) V1

Hash (V5) V5

Hash (V3) V3

Hash (V4) V4

Hash (P1’) Hash (V1), Hash (V2)

Hash (P2) Hash (V3), Hash (V4)

Hash (RH’) Hash (P1’), Hash (P2)

Page 42: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Experimental Setup

• Private Ethereum network• Importing first 1.6 M blocks of the real-world public block chain• geth - Ethereum go client• Machine

• 16 GB of RAM• 2TB Intel 750 series SSD

42

Page 43: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

IO Amplification in Ethereum

• State Trie – 7X IO Amplification• getBalance (addr)• Returns the amount of ether balance present in the account addr• 0.22M account addresses• 1.4M LevelDB gets

43

Page 44: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

IO Amplification in Ethereum

• State Trie – 7X IO Amplification• Worst case – 64X IO Amplification• Key : 256 bits• Every node : 4 bits• Depth of Trie : 64 in the worst case

• Ignoring the IO Amplification introduced by underlying kv store• Considers the first 1.6M blocks of the block chain• Current size of blockchain : 5.9M blocks

44

Page 45: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Caching - Why doesn’t it work?

45

Page 46: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Caching key with value, proof

• Going back to our example• For a 4 bit hex string key-value pairs• 0x20 – 1• 0x2f – 2• 0x51 – 3• 0x5e – 4

46

2

Root Hash

P1

5

f 1

Branching: 0 - f

1

P2

0

2 3

e

4

Page 47: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Caching key with value, proof

• For every key, we cache the value and the Merkle Proof

47

2

Root Hash

P1

5

f 1

Branching: 0 - f

1

P2

0

2 3

e

4

Key Value Proof

0x2f 2 [1, P2, Root Hash]

Page 48: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Caching key with value, proof

• For every key, we cache the value and the Merkle Proof

48

2

Root Hash

P1

5

f 1

Branching: 0 - f

1

P2

0

2 3

e

4

Key Value Proof

0x2f 2 [1, P2, Root Hash]

0x20 1 [2, P2, Root Hash]

Page 49: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Caching key with value, proof

• For every key, we cache the value and the Merkle Proof

49

2

Root Hash

P1

5

f 1

Branching: 0 - f

1

P2

0

2 3

e

4

Key Value Proof

0x2f 2 [1, P2, Root Hash]

0x20 1 [2, P2, Root Hash]

0x51 3 [4, P1, Root Hash]

Page 50: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Caching key with value, proof

• For every key, we cache the value and the Merkle Proof

50

2

Root Hash

P1

5

f 1

Branching: 0 - f

1

P2

0

2 3

e

4

Key Value Proof

0x2f 2 [1, P2, Root Hash]

0x20 1 [2, P2, Root Hash]

0x51 3 [4, P1, Root Hash]

0x5e 4 [3, P1, Root Hash]

Page 51: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

A single update invalidates the whole cache

51

2

Root Hash

P1

5

f 1

Branching: 0 - f

1

P2

0

2 3

e

4

Key Value Proof

0x2f 2 [1, P2, Root Hash]

0x20 1 [2, P2, Root Hash]

0x51 3 [4, P1, Root Hash]

0x5e 4 [3, P1, Root Hash]

Reads can be served from the cache

Page 52: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

A single update invalidates the whole cache

52

2

Root Hash’

P1’

5

f 1

Branching: 0 - f

1

P2

0

5 3

e

4

Key Value Proof

0x2f 2 [1, P2, Root Hash]

0x20 1 [2, P2, Root Hash]

0x51 3 [4, P1, Root Hash]

0x5e 4 [3, P1, Root Hash]

Page 53: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

A single update invalidates the whole cache

53

2

Root Hash

P1

5

f 1

Branching: 0 - f

1

P2

0

5 3

e

4

Key Value Proof

0x2f 5 [1, P2, Root Hash]

0x20 1 [2, P2, Root Hash]

0x51 3 [4, P1, Root Hash]

0x5e 4 [3, P1, Root Hash]

Page 54: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

A single update invalidates the whole cache

54

2

Root Hash

P1’

5

f 1

Branching: 0 - f

1

P2

0

5 3

e

4

Key Value Proof

0x2f 5 [1, P2, Root Hash]

0x20 1 [2, P2, Root Hash]

0x51 3 [4, P1’, Root Hash]

0x5e 4 [3, P1’, Root Hash]

Page 55: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

A single update invalidates the whole cache

55

2

Root Hash’

P1’

5

f 1

Branching: 0 - f

1

P2

0

5 3

e

4

Key Value Proof

0x2f 5 [1, P2, Root Hash’]

0x20 1 [2, P2, Root Hash’]

0x51 3 [4, P1’, Root Hash’]

0x5e 4 [3, P1’, Root Hash’]

Page 56: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

A single update invalidates the whole cache

56

2

Root Hash’

P1

5

f 1

Branching: 0 - f

1

P2

0

5 3

e

4

Key Value Proof

0x2f 5 [1, P2, Root Hash’]

0x20 1 [2, P2, Root Hash’]

0x51 3 [4, P1’, Root Hash’]

0x5e 4 [3, P1’, Root Hash’]

Works only for read-only workloads

Page 57: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Merkelized LSM

57

Page 58: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Why caching didn’t work?

• Tight coupling between any two nodes in the tree• All nodes form a single tree under the same root node

• Tight coupling between Lookup and Authentication• Lookup for a value is done traversing the authenticated data structure

58

Page 59: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Insights behind mLSM

Maintaining Multiple Independent structuresDecoupling Lookup from Authentication

59

Page 60: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Maintaining multiple independent structures

60

Page 61: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Merkelized LSM : Design

61

In-MemoryMemory

Storage

In-memory and On-disk layers

Page 62: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Merkelized Log Structured Merge Tree (mLSM)

62

In memory data is periodically written as binary Merkle trees to storage

In-MemoryMemory

Storage

Page 63: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Merkelized LSM : Design

• Binary Merkle Trees • Reduce the size of the Merkle Proof• Balance data better than Tries

63

Page 64: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Merkelized Log Structured Merge Tree (mLSM)

64Merkle Trees on storage are logically arranged in different levels

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Page 65: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Merkelized Log Structured Merge Tree (mLSM)

65

Compaction is performed once #Trees in a level reaches a threshold

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Compaction

Page 66: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Merkelized Log Structured Merge Tree (mLSM)

66

Compaction is performed once #Trees in a level reaches a threshold

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Compaction

Page 67: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Writes in Merkelized LSM

67Writes are handled in-memory

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Write (Key, Value)

Page 68: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Writes in Merkelized LSM

68Writes are batched and written onto storage

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Write (Key, Value)

Page 69: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Writes in Merkelized LSM

69Numbers of files on reaching the threshold at the level

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Compaction

In-MemoryMemory

Storage

Level 1

Level n

Compaction

Write (Key, Value)

Page 70: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Writes in Merkelized LSM

70

Compaction is performed from lower levels to higher levels

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Compaction

Page 71: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication in mLSM

71

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Page 72: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication in mLSM

72

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Every binary merkle tree on level has a local root

Page 73: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication in mLSM

73

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Global Master Root dynamically computes global Merkle Tree

Page 74: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Authentication in mLSM

74

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Merkle Proof includes the local and the global Merkle proofs

Page 75: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Decoupling lookup from Authentication

75

Page 76: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

LevelDB Cache

76LevelDB cache to store ( Key, Level : Value, Merkle Proof )

Key,Level

Value,Proof

LevelDB cacheIn-Memory

Memory

StorageLevel 0

Level 1

Level n

Page 77: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Reads in mLSM

77

Key,Level

Value,Proof

LevelDB cacheIn-Memory

Memory

StorageLevel 0

Level 1

Level n

Get (key)

Page 78: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Reads in mLSM

78In-memory structure is searched for the value

Key,Level

Value,Proof

LevelDB cacheIn-Memory

Memory

StorageLevel 0

Level 1

Level n

Get (key)

Page 79: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Reads in mLSM

79mLSM is traversed level by level in-order

Key,Level

Value,Proof

LevelDB cacheIn-Memory

Memory

StorageLevel 0

Level 1

Level n

Get (key)

Page 80: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Reads in mLSM

80First occurrence of the key value pair is returned

Key,Level

Value,Proof

LevelDB cacheIn-Memory

Memory

StorageLevel 0

Level 1

Level n

Get (key)

Page 81: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Reads in mLSM

81<Key, level : value, local Merkle proof> are cached

Key,Level

Value,Proof

key, Level

value,Local proof

LevelDB cacheIn-Memory

Memory

StorageLevel 0

Level 1

Level n

Get (key)

Page 82: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Reads in mLSM

82

Key,Level

Value,Proof

key, Level

value,Local Proof

LevelDB cacheIn-Memory

Memory

StorageLevel 0

Level 1

Level n

Get (key)

NOTE: Global Proof is not cached

Page 83: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Reads in mLSM

83

Key,Level

Value,Proof

key, Level

value,Local Proof

LevelDB cacheIn-Memory

Memory

StorageLevel 0

Level 1

Level n

Subsequent reads are served from the cache

Get (key)

Page 84: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Reads in mLSM

84LevelDB cache can be populated once a new binary Merkle tree is created

In-MemoryMemory

Storage

Compaction

Level 0

Level 1

Level n

Key,Level

Value,Proof

key, Level

value,Local Proof

LevelDB cache

Page 85: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Revisiting writes

85

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Writes affect values in a single local tree and the global root

Put (Key, value)

Page 86: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Would writes invalidate the whole cache?

• Global proofs are not cached• Writes don’t invalidate any existing entries• Keys at the same level are over-written when the binary tree is created• Cache will not be invalidated on every write

86

Page 87: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Merkelized LSM : Reviewing the design

• Writes• Buffered in memory• Then written to storage• No in place updates• A write affects one tree and the master root

• Reads• Served from the cache• Or by traversing levels from lowest and till the first occurrence of key is found• Returns value and proof : <local proof, global proof>

87

Page 88: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Merkelized LSM advantages

• Writes are handled in memory : O(1) complexity• Reads :• Served from cache : O(levels in LevelDB cache)• Traversing the mLSM : O(height of mLSM * height of a binary Merkle tree)

88

Reads Complexity Served byCache Hit O(Levels in Cache) LevelDB cache

Cache Miss O(Height of mLSM xHeight of the binary tree)

Traversing mLSM

Page 89: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Merkelized LSM challenges

• Handling read amplification• Overhead of LSM structure is significant for applications with little data• LevelDB cache misses would result in read amplification

• Deterministic Compaction• Replicas : Multiple nodes storing data

89

Page 90: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Deterministic Compaction

90

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Compaction changes the local roots

Compaction

Page 91: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

Deterministic Compaction

91

In-MemoryMemory

StorageLevel 0

Level 1

Level n

Compaction changes the local roots and the global root

Compaction

Page 92: mLSM: Making Authenticated Storage Faster in Ethereum · Merkle Patricia Trie •Similar to Merkle trees •Lookup based on the key structure •Considering 4 bit hex key-value pairs:

mLSM : Authenticated Data Structure

• Minimizes IO Amplification• Maintains multiple mutually independent binary Merkle trees• Decouples lookup from authentication

92