0

I've built a simple blockchain. I want to build a version control of an array of numbers. I want to record additions of new numbers, deletions, and interchanging of numbers. What could be space-efficient way to store these changes? I've considered creating a merkle tree of all the elements of the array and storing the merkle root to check whether the version matches or not, but storing the same data into multiple blocks is redundant and inefficient. Please direct me!

STATE 1: [3,4,5,6]
STATE 2: [3,4,5,6,4]
STATE 3: [4,3,5,6,4]


Block1 HeaderHash: h(h(34)+h(56))
Block2 HeaderHash: h(h(34)+h(56)+h(44))
Block3 HeaderHash: h(h(43)+h(56)+h(44))

P.S. I'm learning the concepts of blockchain and building this from scratch. Please don't judge the project in itself.

Shawn Arthur
  • 11
  • 1
  • 5

1 Answers1

0

For tracking changes you may simply save individual changes for every element in array. In your example it would like this:

STATE 1: [1:3,2:4,3:5,4:6]
STATE 2: [5:4]
STATE 3: [1:1,2:-1]

It won't be space-efficient if there are lots of changes with every state update. But if more then half of the array stays the same, you will benefit.

Merkle Tree is used for verifying individual blocks of data(transactions) received from unknown or little-known sources. It is used in blockchain wallets or torrent clients. It is not used for storing arrays.

denismo
  • 1
  • 1