Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Conversation

@patrick-ogrady
Copy link
Contributor

@patrick-ogrady patrick-ogrady commented Jan 7, 2022

To allow for larger values, we gotta get a little creative 😉 . Multiple units of work can now be completed in a given transaction (as a function of graffitis).

Right now, this PR makes it so you can differentiate the cost to set a large key vs the rate it decays at.

@patrick-ogrady patrick-ogrady force-pushed the value-units branch 2 times, most recently from a640220 to f0ddd33 Compare January 7, 2022 09:57
@patrick-ogrady
Copy link
Contributor Author

patrick-ogrady commented Jan 7, 2022

We may have more luck doing more granular control on difficulty (using an int instead of bits).

I think the multi-work thing is somewhat jank...will change to continuous work calculation to avoid 2^x forced granularity.

k[0] = p
k[1] = parser.Delimiter
binary.LittleEndian.PutUint64(k[2:], uint64(t))
binary.BigEndian.PutUint64(k[2:], t)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found this pretty serious bug in my code lol

@gyuho gyuho force-pushed the value-units branch 2 times, most recently from 6ffbbdf to 0ad71d8 Compare January 9, 2022 01:19
@gyuho
Copy link
Contributor

gyuho commented Jan 9, 2022

lvl=dbug msg=“block building failed: failed verification” err=“insufficient surplus difficulty”
lvl=warn msg=“BuildBlock failed” error=“insufficient surplus difficulty”

Block builds are failing, causing e2e test failures.

@patrick-ogrady
Copy link
Contributor Author

Latest Clues:

fetched estimated difficulty (diff=7, cost=1)
issuing tx 2Rgg8ZnhvgJBRr5ixAYRZARb4zBEpJR1D4kDjgGLPE7qrwMavz (units=10, difficulty=9, surplus=20, blkID=Y9UdWfUz6uUyAqjAXspoSEvA4BfbYe62m5VyenZWrMExFUdFh)
transaction 2Rgg8ZnhvgJBRr5ixAYRZARb4zBEpJR1D4kDjgGLPE7qrwMavz confirmed
raw prefix P55X8AD2z7ugaoB8BQsu27jDhpqTAsczP: units=1 expiry=2022-02-08 02:13:27 +0000 UTC (719h59m58.545538054s remaining)

fetched estimated difficulty (diff=6, cost=60)
issuing tx msN8k866zjv5hJP3qJHh66EA3KP64fr5W8Mc8ZS8vLkBUaCFp (units=11, difficulty=344, surplus=3718, blkID=WM5fUVnnEdKg73mb3ivsurvQ3Rx9kzmWSW1EvjLN1JsyK2tD7)
transaction msN8k866zjv5hJP3qJHh66EA3KP64fr5W8Mc8ZS8vLkBUaCFp confirmed
raw prefix P55X8AD2z7ugaoB8BQsu27jDhpqTAsczP: units=2 expiry=2022-01-24 02:13:28 +0000 UTC (359h59m58.223977384s remaining)

fetched estimated difficulty (diff=5, cost=59)
issuing tx 2X5uQfgjTgqNCSZL5XCmsM4Hww9ByBEgA4kt2vx9h6WoG9rsTo (units=31, difficulty=14, surplus=279, blkID=2AJTt9UuYGfMnFWGhmDp7Rc9KADhd86Wgx52GnPBsSn7U3rPR)

@patrick-ogrady
Copy link
Contributor Author

From the node:

t=2022-01-08T18:21:06-0800 lvl=dbug msg="build context" height=1 difficulty=8 cost=1
t=2022-01-08T18:21:06-0800 lvl=dbug msg="verified block" id=2JTdmkgSnD46YYReQiankLRyENGfYJfyNwAddY34GMptrEx946 parent=2r7sNTjxuMM5BedYkts9kydXfp8typd2AmFdaARbxPcwQE2iCG
t=2022-01-08T18:21:06-0800 lvl=dbug msg="set preference" id=2JTdmkgSnD46YYReQiankLRyENGfYJfyNwAddY34GMptrEx946
t=2022-01-08T18:21:06-0800 lvl=dbug msg="accepted block" id=2JTdmkgSnD46YYReQiankLRyENGfYJfyNwAddY34GMptrEx946
t=2022-01-08T18:21:07-0800 lvl=dbug msg="BuildBlock triggered"
t=2022-01-08T18:21:07-0800 lvl=dbug msg="attempting block building"
t=2022-01-08T18:21:07-0800 lvl=dbug msg="build context" height=2 difficulty=7 cost=60
t=2022-01-08T18:21:07-0800 lvl=dbug msg="block building failed: failed verification" err="insufficient surplus difficulty: required=420 found=176"
t=2022-01-08T18:21:07-0800 lvl=dbug msg="BuildBlock failed" error="insufficient surplus difficulty: required=420 found=176"

@patrick-ogrady patrick-ogrady requested a review from gyuho January 9, 2022 02:54
return nil, nil, err
}
surplusWork += (tx.Difficulty() - context.NextDifficulty) * tx.Units()
surplusWork += (tx.Difficulty() - b.Difficulty) * tx.Units()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good catch!

recommendedC := ctx.NextCost / uint64(recentTxs)
if recommendedC < vm.minBlockCost {
recommendedC = vm.minBlockCost
cPerTx := pCost / uint64(recentTxs) / uint64(ctx.RecentBlockIDs.Len())
Copy link
Contributor

@gyuho gyuho Jan 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here recentTxs == ctx.RecentBlockIDs.Len() via line 83? Why do we do division twice?

And can ctx.RecentTxIDs.Len() be ever 0 (zero devision panic)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • we check that recentTxs is non-zero on 83 to prevent div by 0 (could happen in block height 1)
  • recent block ids can never be 0

}

func PutPrefixInfo(db database.KeyValueWriter, prefix []byte, i *PrefixInfo, lastExpiry int64) error {
func PutPrefixInfo(db database.KeyValueWriter, prefix []byte, i *PrefixInfo, lastExpiry uint64) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

chain/storage.go Outdated
cursor := db.NewIteratorWithStart(startKey)
removals := 0
for cursor.Next() && removals < limit {
for cursor.Next() && removals <= limit {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removals < limit

since this can delete limit + 1?

If we want to adjust prune interval to fullPruneInterval of 1-second on removals=true, vm.pruneCall() can set removals=true when removals >= vm.pruneLimit, or change this for-loop to removals < limit and keep removals == vm.pruneLimit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops...reverted that change.

@patrick-ogrady patrick-ogrady merged commit 62fcfde into master Jan 9, 2022
@patrick-ogrady patrick-ogrady deleted the value-units branch January 9, 2022 16:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants