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

Overflow related to voting power. #1157

Open
alpha-omega-labs opened this issue Sep 10, 2023 · 8 comments
Open

Overflow related to voting power. #1157

alpha-omega-labs opened this issue Sep 10, 2023 · 8 comments

Comments

@alpha-omega-labs
Copy link

Hello,
We had success in migration of genesis.json with your help and used your source code for GenesisL1 upgrade, thank you!
However faced some issue:
after ~71% of updated voting power went online, block production ended with error:
INF received proposal module=consensus proposal={"Type":32,"block_id":{"hash":"FA39B16C041A8FD631784A9CC19EB5F4F0FE4FD8824226175ED201FCE76FA3B8","parts":{"hash ":"85BA0BC72B40D89610F688B70AC47D3D07B56D3A672B456CB91A453F84227452","total":1}},"height":6751391,"pol_round":-1,"round":1,"signature":"zzMzxlERtfDtUyRmu3d3LJTPP9u7Fx B72GN77vcAKVguYS0r8FvliUIcJXPN8PBUohWKAbSO0QXj2abz8KPYBQ==","timestamp":"2023-09-07T19:04:44.225325519Z"} server=node 3:04PM INF received complete proposal block hash=FA39B16C041A8FD631784A9CC19EB5F4F0FE4FD8824226175ED201FCE76FA3B8 height=6751391 module=consensus server=node 3:04PM INF finalizing commit of block hash={} height=6751391 module=consensus num_txs=0 root=E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 server=n ode 3:04PM INF minted coins from module account amount=2684871870626760975el1 from=mint module=x/bank 3:04PM INF executed block height=6751391 module=state num_invalid_txs=0 num_valid_txs=0 server=node 3:04PM ERR CONSENSUS FAILURE!!! err="failed to apply block; error commit failed for application: error changing validator set: total voting power of resulting valset exceeds max 1152921504606846975" module=consensus server=node stack="goroutine 138 [running]:\nruntime/debug.Stack()\n\truntime/debug/stack.go:24 +0x65\ngithub.com/te ndermint/tendermint/consensus.(*State).receiveRoutine.func2()\n\tgithub.com/tendermint/[email protected]/consensus/state.go:732 +0x4c\npanic({0x26c4320, 0xc001db119 0})\n\truntime/panic.go:884 +0x213\ngithub.com/tendermint/tendermint/consensus.(*State).finalizeCommit(0xc0001f9880, 0x67049f)\n\tgithub.com/tendermint/tendermint@v0. 34.29/consensus/state.go:1670 +0xfab\ngithub.com/tendermint/tendermint/consensus.(*State).tryFinalizeCommit(0xc0001f9880, 0x67049f)\n\tgithub.com/tendermint/tendermin [email protected]/consensus/state.go:1570 +0x2ff\ngithub.com/tendermint/tendermint/consensus.(*State).enterCommit.func1()\n\tgithub.com/tendermint/[email protected]/consen sus/state.go:1505 +0xaa\ngithub.com/tendermint/tendermint/consensus.(*State).enterCommit(0xc0001f9880, 0x67049f, 0x1)\n\tgithub.com/tendermint/[email protected]/con sensus/state.go:1543 +0xccf\ngithub.com/tendermint/tendermint/consensus.(*State).addVote(0xc0001f9880, 0xc001d5c140, {0xc0912c2ed0, 0x28})\n\tgithub.com/tendermint/te [email protected]/consensus/state.go:2164 +0x18dc\ngithub.com/tendermint/tendermint/consensus.(*State).tryAddVote(0xc0001f9880, 0xc001d5c140, {0xc0912c2ed0?, 0xc004ef dc08?})\n\tgithub.com/tendermint/[email protected]/consensus/state.go:1962 +0x2c\ngithub.com/tendermint/tendermint/consensus.(*State).handleMsg(0xc0001f9880, {{0x3c 77020, 0xc00291b500}, {0xc0912c2ed0, 0x28}})\n\tgithub.com/tendermint/[email protected]/consensus/state.go:861 +0x3ff\ngithub.com/tendermint/tendermint/consensus.(* State).receiveRoutine(0xc0001f9880, 0x0)\n\tgithub.com/tendermint/[email protected]/consensus/state.go:768 +0x3f0\ncreated by github.com/tendermint/tendermint/conse nsus.(*State).OnStart\n\tgithub.com/tendermint/[email protected]/consensus/state.go:379 +0x12d\n" 3:04PM INF service stop impl={"Logger":{}} module=consensus msg={} server=node wal=/root/.genesisd/data/cs.wal/wal 3:04PM INF service stop impl={"Dir":"/root/.genesisd/data/cs.wal","Head":{"ID":"aFqa318hpH7x:/root/.genesisd/data/cs.wal/wal","Path":"/root/.genesisd/data/cs.wal/wal" },"ID":"group:aFqa318hpH7x:/root/.genesisd/data/cs.wal/wal","Logger":{}} module=consensus msg={} server=node wal=/root/.genesisd/data/cs.wal/wal

It looks like there is some miscalculation of voting power somewhere, maybe related to denomination.
Can you please point where it can be?
Thank you

@zenodeapp
Copy link

zenodeapp commented Sep 10, 2023

I am currently trying to see where exactly the problem could lie. I'm no Golang developer. Though trying to debug this with some understanding of programming.

See the verifyUpdates function in the validator_set.go file. The if-statement at line 448 seems to trigger this Error.

https://github.com/cometbft/cometbft/blob/main/types/validator_set.go#L427

func verifyUpdates(
	updates []*Validator,
	vals *ValidatorSet,
	removedPower int64,
) (tvpAfterUpdatesBeforeRemovals int64, err error) {
	delta := func(update *Validator, vals *ValidatorSet) int64 {
		_, val := vals.GetByAddress(update.Address)
		if val != nil {
			return update.VotingPower - val.VotingPower
		}
		return update.VotingPower
	}

	updatesCopy := validatorListCopy(updates)
	sort.Slice(updatesCopy, func(i, j int) bool {
		return delta(updatesCopy[i], vals) < delta(updatesCopy[j], vals)
	})

	tvpAfterRemovals := vals.TotalVotingPower() - removedPower
	for _, upd := range updatesCopy {
		tvpAfterRemovals += delta(upd, vals)
		if tvpAfterRemovals > MaxTotalVotingPower {
			return 0, ErrTotalVotingPowerOverflow
		}
	}
	return tvpAfterRemovals + removedPower, nil
}

Some observations:

  1. In line 445:
    tvpAfterRemovals := vals.TotalVotingPower() - removedPower

does not lead to the Panic error it could create (vals.TotalVotingPower() => TotalVotingPower() => updateTotalVotingPower()).

func (vals *ValidatorSet) TotalVotingPower() int64 {
	if vals.totalVotingPower == 0 {
		vals.updateTotalVotingPower()
	}
	return vals.totalVotingPower
}

and

func (vals *ValidatorSet) updateTotalVotingPower() {
	sum := int64(0)
	for _, val := range vals.Validators {
		// mind overflow
		sum = safeAddClip(sum, val.VotingPower)
		if sum > MaxTotalVotingPower {
			panic(fmt.Sprintf(
				"Total voting power should be guarded to not exceed %v; got: %v",
				MaxTotalVotingPower,
				sum))
		}
	}

	vals.totalVotingPower = sum
}

This makes me believe this part is not the culprit. Unless for some reason the cached totalVotingPower in the ValidatorSet struct is a value that became too big at a certain point and doesn't get updated to the correct value now, because it only gets updated whenever the totalVotingPower equals 0, else it keeps getting it from cache. (see if vals.totalVotingPower == 0).

Though unsure if this could be the issue.

  1. Another potential cause was that the Voting Powers were wrong (as in having numbers that are too big; for instance because of using the incorrect denominator). Though I believe this is not the case for when I query the status of my Node (localhost/status) or status of all nodes (localhost/validators), I see VPs based on L1 (which is the biggest denominator and main symbol for the token). Which, when added together wouldn't by far get to the max value of 64bit/8 (MaxTotalVotingPower = int64(math.MaxInt64) / 8).

  2. If supposedly for removedPower in line 445 a big negative number would be inserted then that may lead to tvpAfterRemovals to become a huge positive number in line 445. I haven't researched this well enough to see if this happens or could happen. It's unlikely, nevertheless possible.

  3. Or something weird is happening in tvpAfterRemovals += delta(upd, vals). But not seeing what that could be at the moment.

Just tried to research this a bit and see if anything could be of use here. I'll continue checking into this, though again, I'm no Golang developer and not really sure how I could actually debug this.

@yihuang
Copy link
Collaborator

yihuang commented Sep 11, 2023

may have something to do with decimal places.

@alpha-omega-labs
Copy link
Author

may have something to do with decimal places.

Yes, that is one of main concerns, maybe you can point where it can be in code? cronos have same as ETH denomination, right? So code should be compatible with state in theory.

@zenodeapp
Copy link

may have something to do with decimal places.

Doing genesisd query tendermint-validator-set gives:

block_height: "6751391"
total: "44"
validators:
- address: genesisvalcons1e92m950nsa9qnnp3qckj700xsqeg2hqsgylwzr
  proposer_priority: "-10232024"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: aK2K0A4Hr/UqZpeS4GNrQJjsWprL/0ekp8HYMWOc9GU=
  voting_power: "988923"
- address: genesisvalcons1fj5dmfyv5tl4yzx99n8dyqe5ggew8vc76hsjkx
  proposer_priority: "950584"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: 14bnE1fd9AgghBJFQrjWzEqfDv9CfNdEfpuegpQHeiQ=
  voting_power: "950584"
- address: genesisvalcons14rp7hduu54kkjyzu95nqfvffdg3pn6ku8p0stc
  proposer_priority: "854400"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: U6Ea8DWKliIJeIlk5M697xGgrHHWESo5iDHuDd9ew2M=
  voting_power: "854400"
- address: genesisvalcons1q4kcvjsuhazsf34t2avz63srxh98aucrn2vgyc
  proposer_priority: "840219"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: 59zxeRETLjBs774quwwcHa0roPNDtW83u90GH3v4yLw=
  voting_power: "840219"
- address: genesisvalcons1vlkxnq5xqs6ta2rngj339hl2uqh5w53gwdhmqh
  proposer_priority: "659851"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: guQbAG/6/Uu+g+8lnw0lEtm2w8/fN6GXimHbyTxgMVA=
  voting_power: "659851"
- address: genesisvalcons133k7q6d7w7zdl3d75jtkspg2ltdk500ll9e6cy
  proposer_priority: "597875"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: KuqkZUftROHRo+AZ2hrOjIqAX5g9ttb0rklcZHNpIa8=
  voting_power: "597875"
- address: genesisvalcons1f8u9peaumcq638v2sv6x2hkau4mwzdcmas52ag
  proposer_priority: "566318"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: J/VhQMUcFlO7KEkffymwDgx4rN95nxsxoo6MwmNun4c=
  voting_power: "566318"
- address: genesisvalcons1dpjk6wl603tywj0l358z3xq8snawpt95nyz4ge
  proposer_priority: "514220"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: 3JOkKXxTv/w1k4UlAXc5f4poLOZRddDvBx1ph0qWAhY=
  voting_power: "514220"
- address: genesisvalcons1ms8melhj0pkdvxq3f7jz7g206uuac726rmkl2w
  proposer_priority: "489566"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: e4U/EW8WIvdByLNungYaUsxp/u+36NtboRRwj2AUjqE=
  voting_power: "489566"
- address: genesisvalcons1kesmyxuvajczu8mwy35zeksp729muva3revutp
  proposer_priority: "482475"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: uuFSqNq86CHcUIlljg7u6QjlrCYyLgyGHBJGwsMtv3Y=
  voting_power: "482475"
- address: genesisvalcons1yph36vnl8g6f8k7mffaq6yrldv0dp2y9mhw0tu
  proposer_priority: "468897"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: Bz7TeobiuuoyO99/+YDKOMPMUEsNt4ox1AQYwf7tbfo=
  voting_power: "468897"
- address: genesisvalcons1tsx0tvr5l9zc0cxgcu3fa2qap5amycmrfed8yy
  proposer_priority: "366857"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: E5bV3F9lk9I4Goh/K2fHtqfCa+tT0a5EZrX6jrVoNWc=
  voting_power: "366857"
- address: genesisvalcons1vs7sgcudfa2eaxsg6k9a7sw6vtedf7lp8pk77x
  proposer_priority: "325145"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: cpi3htlwvGVZncjGFPInBUINi0JHvBE04cfGY3Is63k=
  voting_power: "325145"
- address: genesisvalcons1c3a3duuk209g76k69hzrqne5fsa9fskw8gq324
  proposer_priority: "277376"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: wmE/g+QNsAXET4tSL+I0t+rM/Jgm3RQ0PUwdHxWexfs=
  voting_power: "277376"
- address: genesisvalcons1wjazxn9cc8a73ed7m4l40085ly37fgd25ws5jg
  proposer_priority: "263458"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: kZ6IDjAck7zaHZULSxO8GEMyntYGsrEmWpTTQwMpTyw=
  voting_power: "263458"
- address: genesisvalcons1kvc4enxp89ac0pfkl4tda5cxj6x2w3wpnn2677
  proposer_priority: "260401"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: cy+zsnQ4MI3Z8fnTuQeQilqK1hrrXthYCZMkIvNpytY=
  voting_power: "260401"
- address: genesisvalcons17v3lawy9ckah9kqkwj292u7gckwhuv33hdtkau
  proposer_priority: "252596"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: N440sp1OeV60AFmgLVrnOUHU45mS6P3zS4jC6vUVWV4=
  voting_power: "252596"
- address: genesisvalcons1ay620rvg526j758dv040ms7d7yvkn7rsgh7zq9
  proposer_priority: "213158"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: 88GoVooIWEAr4gW7zLjjmL2heHSnW0mUoc146TpXkBg=
  voting_power: "213158"
- address: genesisvalcons1esdz343l403s8vk5v2n4nyaasn3ry047kc7pkn
  proposer_priority: "195345"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: 0TlHXEQ/FDmF9l/kLaOzfsOp2M0Ff41thpkQViBL3cU=
  voting_power: "195345"
- address: genesisvalcons125lnczr89ksttwwhra0h5r7f32puupcvhrwnvd
  proposer_priority: "192757"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: xVmVFyd9Qw7IaPU04VyA6K6fvRhUGZD6yVB9Dwrkm0s=
  voting_power: "192757"
- address: genesisvalcons103xxdc4gdsqfvweeeuu2kfw7trmq7p0c3wl6vq
  proposer_priority: "186417"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: VE/natC5t474rLcoZUJkUm05eTu4Kp2BIwEp0XIKZJA=
  voting_power: "186417"
- address: genesisvalcons1p5sqyst4pfz9fucza53vl4f77cu5hmwxywtwdu
  proposer_priority: "134690"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: FRrWC5KGS5esx9T7S7adECUlNBtywDKxIGQO8RUKBrQ=
  voting_power: "134690"
- address: genesisvalcons163de4vhlg95eh53fuardvgysa7st55src7q9rw
  proposer_priority: "95353"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: 6OjyuFZmKCIYYz0zJrrLFjjeg/SyuFwLiA1osq2hnVI=
  voting_power: "95353"
- address: genesisvalcons13rdw90datx2jk8uqlllus2mx5s0znqmyu3cqp6
  proposer_priority: "90366"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: jSBxepnhhG9woK+dkANoL/a/sFD8VvXxHxnmRUoTfs0=
  voting_power: "90366"
- address: genesisvalcons1wsr9fftzta89w0r3pae7the2mx2d8lswttgm6q
  proposer_priority: "78414"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: StmSMOJiDU92w+kxD78Xi4y/SmzZRYv9Vszai+1tUmM=
  voting_power: "78414"
- address: genesisvalcons1645mcv5umarsa37ynd22kpjes75536jmdkhsjg
  proposer_priority: "73815"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: OgSNy2Aqu9EgmG3DrzMpYCPfvwfQh9VAAf4ezrvTNO8=
  voting_power: "73815"
- address: genesisvalcons14aw2w64efreruu0xr9mwxyruzzxlqee0c5qqee
  proposer_priority: "70534"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: hQweDcxwOQiZxdaOn3JR0eHPuimADzxZTnO/hEK50m4=
  voting_power: "70534"
- address: genesisvalcons1a7xj904s3kvtyrqktsnwnmy0vxmakj8qlc60rn
  proposer_priority: "62461"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: R6e9Sp4iOFXWbC3qd4wRcyfNkZUkrpOiY+xp17Heovk=
  voting_power: "62461"
- address: genesisvalcons1rn9wxj5f5nrvc9k87nrewcc70e6atjhhthduq0
  proposer_priority: "59171"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: mFk+kF47UKv7IFs42ewZVPvTVcCQxa/xvb1n1nvpO/U=
  voting_power: "59171"
- address: genesisvalcons15yphwxg65cxye8kl4dyvr00n9n3mezera5pz4d
  proposer_priority: "58097"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: lcaOUPMkkbku1m8f34uUaAPU3QkS8pCuNON05iWesRw=
  voting_power: "58097"
- address: genesisvalcons1eysw3a3y0ghvf4mexm3pmr4d9vkwv6pgyak0rp
  proposer_priority: "56412"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: KqT02Nxei4BTj4wqXhTYRd1dXUucC/Q6IRzPleFBklw=
  voting_power: "56412"
- address: genesisvalcons1jka0j43f2j8ufh2en4zas96q7e4w9huve5duz5
  proposer_priority: "56184"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: u0uGvbY3uf2YPm4KWySJNPQY6c/JHw1M5K0HdIJ2GNg=
  voting_power: "56184"
- address: genesisvalcons1hvj3pw6ku2t53nczqr4dkvnsp7vr59u0gmepp2
  proposer_priority: "55480"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: b0FUJ15u69mfPs7mMDwZwhvuxYycQ3iwBUNJ+rV4hiI=
  voting_power: "55480"
- address: genesisvalcons19gtvwac6yynky6jx3tryehrzng4sn9x7g2qpty
  proposer_priority: "51604"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: ck2bR44hWBH/6TpSiki+aZ4WPhKDK1iL/2z7VPH+4uc=
  voting_power: "51604"
- address: genesisvalcons15g78zkspxwwn2hxe3l2pzu2p8dy0pml26cnchj
  proposer_priority: "48631"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: XXckqzHHmpzU4udw7cWC/jVsbKfD8ODqlV6/VxE2tno=
  voting_power: "48631"
- address: genesisvalcons1pmz8dcv8lt05lxqgdq5ueavj3xs2tchakagp9p
  proposer_priority: "48011"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: uS1IhfogRhDOh2NBNidomjt+DVNwAW82P+aWFjtCDo0=
  voting_power: "48011"
- address: genesisvalcons1p6jpg5jl6ngvj8c65u095feg5kqhq3m6yvrfq8
  proposer_priority: "39021"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: VYEQ6H0e2vx/wCtG8RrTy3JVA3+kg5ihSiJ8Oj8M8fo=
  voting_power: "39021"
- address: genesisvalcons1ye5r59p2mzmxkm6dhqrkddghq28g5hx7mmtct8
  proposer_priority: "38655"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: moucIfBYik+YWHJTuxIlFXPW5i6uDucxt9uWEkixpk4=
  voting_power: "38655"
- address: genesisvalcons1l3lgsdj0guaqlpumth99ecvxguahf8x5gcp3dl
  proposer_priority: "35661"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: XRv1dl6dAFP3QLi5wdVs9vcPWyF0zaz0SOHwbQ8QQ8c=
  voting_power: "35661"
- address: genesisvalcons1mas7e4rsf3ly4megty8g2xe6xthw750969j3vd
  proposer_priority: "35061"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: lLT6mxvyqqG2cebV8e+b0FPGaNJ7rh0jiknpmKY8WVE=
  voting_power: "35061"
- address: genesisvalcons1ufgj6u5k075w3l0tjst00q0f7kspfnjw806j5l
  proposer_priority: "28395"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: OmmcYpp7wtZeZltXou3GTWegmmllmI6/LzLGZM3NNnw=
  voting_power: "28395"
- address: genesisvalcons1t8rh5v44z5w4x0v9p5q60nq5r9lvlpaay2mqsu
  proposer_priority: "25768"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: heQWd9bhdX60vk+YnpkEZb+g97lhm8Nnp0ul6gNrjRg=
  voting_power: "25768"
- address: genesisvalcons1p2z9x9y0y2xlrml4fm6temxme78wvm6sh63g2r
  proposer_priority: "18856"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: aHRLm1zTYIn8sAMVm5nV9QwZV1dwNzaDMS7P3yKJXR8=
  voting_power: "18856"
- address: genesisvalcons1nqakawrqqv68jp9l9m9mcxfzc7gsk0yqup8nvy
  proposer_priority: "13469"
  pub_key:
    type: tendermint/PubKeyEd25519
    value: 2qaFfSK005NZYiOTBN9Xph/KFq27lwDM1bTKW3fkbdM=
  voting_power: "13469"

Seems to look okay and the total is far below the voting power for the overflow error (sum: 11220947).

@zenodeapp
Copy link

zenodeapp commented Sep 11, 2023

Only places where I see values that have decimals or large values and are related to validators are in keys "delegator_shares" "shares" and "tokens" in our genesis.json state.

example:

"shares":"10950000000000000000.000000000000000000"
"delegator_shares":"1200120012001200120.012001200120012002"
"tokens": "11803899998066893825"

But I expect it would gather voting power from the "power" key and not these.

Thought I should give this extra information, perhaps it gives more insight to our situation.

Also is there a way to debug this better?

EDIT: So, in retrospect (I still may be wrong). consensus power is calculated via 'tokens'. Power is the result of this calculation.

@zenodeapp
Copy link

zenodeapp commented Sep 13, 2023

@yihuang Okay, so we haven't tested this out yet, but it's highly likely that this was causing the issue. We never changed the DefaultPowerReduction inside the app.go file. As our tokens are 18-decimals and saved in such a format in the "tokens" key of a validator. See PR here.

The default value for DefaultPowerReduction is normally set to NewIntFromUint64(1000000) (see here). I've also checked the state file of cronos and here "tokens" are also based on them being able to only have 6 decimals.

Now a question might be whether it is okay for us to change the app.go file to be able to make calculations with 18 decimals or will this lead to implications once the blockchain starts?

Are there any more places we'd have to configure this to be 18-decimals?

@zenodeapp
Copy link

zenodeapp commented Sep 13, 2023

For those who need some more info concerning this issue (this file in the cosmos-sdk gave some more insight to this):
https://github.com/cosmos/cosmos-sdk/blob/v0.46.15/x/staking/keeper/val_state_change.go

totalPower = totalPower.Add(sdk.NewInt(newPower)) --calculates the totalPower.
newPower := validator.ConsensusPower(powerReduction) --is important, as this calculates the consensus power for a validator.

It's a bit unfortunate how the naming of "power" is in here, for newPower is based on Voting Power (Consensus blockchain stuff) and powerReduction is based on Math (to the power of/exponent).

Now checking the Method ConsensusPower we see that this method calculates the Power for a validator based on three things:

  1. If validator is bonded or not.
  2. How many tokens this validator has.
  3. Which power reduction are we going to use?

If the validator isn't bonded, then it simply returns 0 as consensus power. But if the validator is bonded, it calculates its consensus power based on dividing the amount of tokens with the given power reduction.

An example: if a validator has 10L1, our state file states that this validator has "tokens: 10000000000000000000", (18 0's extra added). So in our case, to calculate consensus power, we would have to give a power reduction of 10^18, in order to get 10 back.

Which doesn't happen, if the DefaultPowerReduction isn't set to 10^18. The default value of 10^6 removes 6 zeros (see here). Thus, this leads to an enormous total voting power value being read in CometBFT that exceeds the limit of CometBFT's maxInt value of Uint64 / 8, which is about 2^60 - 1.

@yihuang
Copy link
Collaborator

yihuang commented Sep 13, 2023

Yep, that's a common overlook, you can also checkout evmos's setting for this, they have 18 decimals as well

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

No branches or pull requests

3 participants