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

core/dutydb: refactor aggregation bits #182

Merged
merged 2 commits into from
Mar 5, 2022
Merged

core/dutydb: refactor aggregation bits #182

merged 2 commits into from
Mar 5, 2022

Conversation

corverroos
Copy link
Contributor

Simplifies the pubkey lookup when an attestation is submitted. Instead of using aggregation bits, use the validator committee index explicitly.

category: refactor
ticket: #165

@corverroos corverroos changed the title core/dutydb: refactor aggregation bits to validator committee index bits core/dutydb: refactor aggregation bits Mar 5, 2022
@codecov
Copy link

codecov bot commented Mar 5, 2022

Codecov Report

❗ No coverage uploaded for pull request base (main@f478324). Click here to learn what that means.
The diff coverage is n/a.

❗ Current head f313e6a differs from pull request most recent head 0c40087. Consider uploading reports for the commit 0c40087 to get more accurate results

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #182   +/-   ##
=======================================
  Coverage        ?   54.44%           
=======================================
  Files           ?       39           
  Lines           ?     2439           
  Branches        ?        0           
=======================================
  Hits            ?     1328           
  Misses          ?      977           
  Partials        ?      134           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f478324...0c40087. Read the comment docs.

core/validatorapi/validatorapi.go Show resolved Hide resolved
Comment on lines -24 to -48
// getAggBitsHex returns the aggregation bits hex for a committee
// with length validators and the validator as index set to true.
func getAggBitsHex(length, index uint64) (string, error) {
if length == 0 {
return "0x00", nil
}

if length <= index {
return "", errors.New("agg bit index not smaller than length",
z.U64("length", length), z.U64("index", index))
}

extra := uint64(1)
if length%8 == 0 {
extra = 0
}

buckets := length/8 + extra
bitList := make([]byte, buckets)

offset := buckets - 1 - index/8
bitList[offset] = byte(0x01 << (index % 8))

return "0x" + hex.EncodeToString(bitList), nil
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is how the VC calculates the value of aggbits it includes in the attestation

it gets the inputs values from AttestationDuty

aggbits := getAggBitsHex(duty.CommitteeLength, duty.ValidatorCommitteeIndex)

Co-authored-by: Dhruv Bodani <dhruvbodani2510@gmail.com>
@corverroos corverroos merged commit 7a504ab into main Mar 5, 2022
@corverroos corverroos deleted the corver/aggbits branch March 5, 2022 13:02
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

Successfully merging this pull request may close these issues.

2 participants