mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
refactor: DA
This commit is contained in:
parent
f77f62ec5f
commit
7e03062283
7 changed files with 105 additions and 56 deletions
File diff suppressed because one or more lines are too long
|
|
@ -69,7 +69,7 @@ func (suite *DASignersTestSuite) registerSigner(testSigner common.Address, sk *b
|
||||||
suite.Assert().NoError(err)
|
suite.Assert().NoError(err)
|
||||||
|
|
||||||
oldLogs := suite.statedb.Logs()
|
oldLogs := suite.statedb.Logs()
|
||||||
_, err = suite.runTx(input, testSigner, 10000000, uint256.NewInt(0), false)
|
_, err = suite.runTx(input, suite.dasigners.getRegistry(), 10000000, uint256.NewInt(0), false)
|
||||||
suite.Assert().NoError(err)
|
suite.Assert().NoError(err)
|
||||||
logs := suite.statedb.Logs()
|
logs := suite.statedb.Logs()
|
||||||
suite.Assert().EqualValues(len(logs), len(oldLogs)+2)
|
suite.Assert().EqualValues(len(logs), len(oldLogs)+2)
|
||||||
|
|
@ -110,18 +110,20 @@ func (suite *DASignersTestSuite) updateSocket(testSigner common.Address, signer
|
||||||
signer.Socket = "0.0.0.0:2345"
|
signer.Socket = "0.0.0.0:2345"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *DASignersTestSuite) registerEpoch(testSigner common.Address, sk *big.Int) {
|
func (suite *DASignersTestSuite) registerEpoch(testSigner common.Address, sk *big.Int, votes *big.Int) {
|
||||||
epoch := suite.dasigners.epochNumber(suite.evm) + 1
|
epoch := suite.dasigners.epochNumber(suite.evm) + 1
|
||||||
hash := dasigners.EpochRegistrationHash(testSigner, epoch, suite.evm.chainConfig.ChainID)
|
hash := dasigners.EpochRegistrationHash(testSigner, epoch, suite.evm.chainConfig.ChainID)
|
||||||
signature := new(bn254.G1Affine).ScalarMultiplication(hash, sk)
|
signature := new(bn254.G1Affine).ScalarMultiplication(hash, sk)
|
||||||
|
|
||||||
input, err := suite.abi.Pack(
|
input, err := suite.abi.Pack(
|
||||||
"registerNextEpoch",
|
"registerNextEpoch",
|
||||||
|
testSigner,
|
||||||
dasigners.NewBN254G1Point(bn254util.SerializeG1(signature)),
|
dasigners.NewBN254G1Point(bn254util.SerializeG1(signature)),
|
||||||
|
votes,
|
||||||
)
|
)
|
||||||
suite.Assert().NoError(err)
|
suite.Assert().NoError(err)
|
||||||
|
|
||||||
_, err = suite.runTx(input, testSigner, 10000000, uint256.NewInt(0), false)
|
_, err = suite.runTx(input, suite.dasigners.getRegistry(), 10000000, uint256.NewInt(0), false)
|
||||||
suite.Assert().NoError(err)
|
suite.Assert().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -264,8 +266,8 @@ func (suite *DASignersTestSuite) Test_DASigners() {
|
||||||
signer2 := suite.registerSigner(suite.signerTwo, big.NewInt(11))
|
signer2 := suite.registerSigner(suite.signerTwo, big.NewInt(11))
|
||||||
suite.updateSocket(suite.signerOne, signer1)
|
suite.updateSocket(suite.signerOne, signer1)
|
||||||
suite.updateSocket(suite.signerTwo, signer2)
|
suite.updateSocket(suite.signerTwo, signer2)
|
||||||
suite.registerEpoch(suite.signerOne, big.NewInt(1))
|
suite.registerEpoch(suite.signerOne, big.NewInt(1), big.NewInt(1))
|
||||||
suite.registerEpoch(suite.signerTwo, big.NewInt(11))
|
suite.registerEpoch(suite.signerTwo, big.NewInt(11), big.NewInt(2))
|
||||||
// move to next epochs
|
// move to next epochs
|
||||||
daparams := suite.dasigners.params()
|
daparams := suite.dasigners.params()
|
||||||
suite.queryEpochNumber(suite.signerOne, big.NewInt(0))
|
suite.queryEpochNumber(suite.signerOne, big.NewInt(0))
|
||||||
|
|
@ -274,8 +276,8 @@ func (suite *DASignersTestSuite) Test_DASigners() {
|
||||||
suite.queryEpochNumber(suite.signerOne, big.NewInt(1))
|
suite.queryEpochNumber(suite.signerOne, big.NewInt(1))
|
||||||
suite.makeEpoch(suite.signerOne)
|
suite.makeEpoch(suite.signerOne)
|
||||||
suite.queryEpochNumber(suite.signerOne, big.NewInt(1))
|
suite.queryEpochNumber(suite.signerOne, big.NewInt(1))
|
||||||
suite.registerEpoch(suite.signerOne, big.NewInt(1))
|
suite.registerEpoch(suite.signerOne, big.NewInt(1), big.NewInt(1))
|
||||||
suite.registerEpoch(suite.signerTwo, big.NewInt(11))
|
suite.registerEpoch(suite.signerTwo, big.NewInt(11), big.NewInt(2))
|
||||||
// move to epoch 2
|
// move to epoch 2
|
||||||
suite.evm.Context.BlockNumber = suite.evm.Context.BlockNumber.Add(suite.evm.Context.BlockNumber, daparams.EpochBlocks)
|
suite.evm.Context.BlockNumber = suite.evm.Context.BlockNumber.Add(suite.evm.Context.BlockNumber, daparams.EpochBlocks)
|
||||||
suite.makeEpoch(suite.signerOne)
|
suite.makeEpoch(suite.signerOne)
|
||||||
|
|
@ -307,10 +309,8 @@ func (suite *DASignersTestSuite) Test_DASigners() {
|
||||||
twoPos = min(twoPos, i)
|
twoPos = min(twoPos, i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
suite.Assert().EqualValues(cnt[suite.signerOne], len(quorum)/2)
|
suite.Assert().EqualValues(cnt[suite.signerOne], len(quorum)/3)
|
||||||
suite.Assert().EqualValues(cnt[suite.signerTwo], len(quorum)/2)
|
suite.Assert().EqualValues(cnt[suite.signerTwo], len(quorum)*2/3)
|
||||||
// suite.Assert().EqualValues(cnt[suite.signerOne], len(quorum)/3)
|
|
||||||
// suite.Assert().EqualValues(cnt[suite.signerTwo], len(quorum)*2/3)
|
|
||||||
|
|
||||||
bitMap := make([]byte, len(quorum)/8)
|
bitMap := make([]byte, len(quorum)/8)
|
||||||
bitMap[onePos/8] |= 1 << (onePos % 8)
|
bitMap[onePos/8] |= 1 << (onePos % 8)
|
||||||
|
|
@ -321,8 +321,7 @@ func (suite *DASignersTestSuite) Test_DASigners() {
|
||||||
}{
|
}{
|
||||||
AggPkG1: dasigners.NewBN254G1Point(bn254util.SerializeG1(new(bn254.G1Affine).ScalarMultiplication(bn254util.GetG1Generator(), big.NewInt(1)))),
|
AggPkG1: dasigners.NewBN254G1Point(bn254util.SerializeG1(new(bn254.G1Affine).ScalarMultiplication(bn254util.GetG1Generator(), big.NewInt(1)))),
|
||||||
Total: big.NewInt(int64(len(quorum))),
|
Total: big.NewInt(int64(len(quorum))),
|
||||||
Hit: big.NewInt(int64(len(quorum) / 2)),
|
Hit: big.NewInt(int64(len(quorum) / 3)),
|
||||||
// Hit: big.NewInt(int64(len(quorum) / 3)),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
bitMap[twoPos/8] |= 1 << (twoPos % 8)
|
bitMap[twoPos/8] |= 1 << (twoPos % 8)
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -71,12 +71,13 @@ func SerializeG2(p BN254G2Point) []byte {
|
||||||
var (
|
var (
|
||||||
signerKey = []byte{0x00} // signer => registered signer info
|
signerKey = []byte{0x00} // signer => registered signer info
|
||||||
quorumKey = []byte{0x01} // epoch => quorumId => quorum
|
quorumKey = []byte{0x01} // epoch => quorumId => quorum
|
||||||
registrationKey = []byte{0x02} // signer => signature hash
|
registrationKey = []byte{0x02} // epoch => signer => signature(vrf)
|
||||||
quorumCountKey = []byte{0x03} // epoch => quorum count
|
votesKey = []byte{0x03} // epoch => signer => votes
|
||||||
epochNumberKey = []byte{0x04} // epoch number
|
quorumCountKey = []byte{0x04} // epoch => quorum count
|
||||||
epochBlockKey = []byte{0x05} // epoch number => block number
|
epochNumberKey = []byte{0x05} // epoch number
|
||||||
epochRegistrationKey = []byte{0x06} // epoch number => registration count
|
epochBlockKey = []byte{0x06} // epoch number => block number
|
||||||
epochRegisteredSignerKey = []byte{0x07} // epoch number => index => signer
|
epochRegistrationKey = []byte{0x07} // epoch number => registration count
|
||||||
|
epochRegisteredSignerKey = []byte{0x08} // epoch number => index => signer
|
||||||
)
|
)
|
||||||
|
|
||||||
func SignerKey(account common.Address) common.Hash {
|
func SignerKey(account common.Address) common.Hash {
|
||||||
|
|
@ -91,6 +92,10 @@ func RegistrationKey(epochNumber uint64, account common.Address) common.Hash {
|
||||||
return crypto.Keccak256Hash(append(append(registrationKey, common.Uint64ToBytes(epochNumber)...), account.Bytes()...))
|
return crypto.Keccak256Hash(append(append(registrationKey, common.Uint64ToBytes(epochNumber)...), account.Bytes()...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func VotesKey(epochNumber uint64, account common.Address) common.Hash {
|
||||||
|
return crypto.Keccak256Hash(append(append(votesKey, common.Uint64ToBytes(epochNumber)...), account.Bytes()...))
|
||||||
|
}
|
||||||
|
|
||||||
func QuorumCountKey(epochNumber uint64) common.Hash {
|
func QuorumCountKey(epochNumber uint64) common.Hash {
|
||||||
return crypto.Keccak256Hash(append(quorumCountKey, common.Uint64ToBytes(epochNumber)...))
|
return crypto.Keccak256Hash(append(quorumCountKey, common.Uint64ToBytes(epochNumber)...))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,6 @@ package precompiles
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrSenderNotOrigin = errors.New("sender not origin")
|
ErrSenderNotOrigin = errors.New("sender not origin")
|
||||||
|
ErrSenderNotRegistry = errors.New("sender not registry")
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -336,6 +336,11 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"inputs": [
|
"inputs": [
|
||||||
|
{
|
||||||
|
"internalType": "address",
|
||||||
|
"name": "signer",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"components": [
|
"components": [
|
||||||
{
|
{
|
||||||
|
|
@ -352,6 +357,11 @@
|
||||||
"internalType": "struct BN254.G1Point",
|
"internalType": "struct BN254.G1Point",
|
||||||
"name": "_signature",
|
"name": "_signature",
|
||||||
"type": "tuple"
|
"type": "tuple"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"internalType": "uint256",
|
||||||
|
"name": "votes",
|
||||||
|
"type": "uint256"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"name": "registerNextEpoch",
|
"name": "registerNextEpoch",
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ interface IDASigners {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Params {
|
struct Params {
|
||||||
uint tokensPerVote;
|
uint tokensPerVote; // deprecated
|
||||||
uint maxVotesPerSigner;
|
uint maxVotesPerSigner;
|
||||||
uint maxQuorums;
|
uint maxQuorums;
|
||||||
uint epochBlocks;
|
uint epochBlocks;
|
||||||
|
|
@ -75,7 +75,11 @@ interface IDASigners {
|
||||||
uint _epoch
|
uint _epoch
|
||||||
) external view returns (bool);
|
) external view returns (bool);
|
||||||
|
|
||||||
function registerNextEpoch(BN254.G1Point memory _signature) external;
|
function registerNextEpoch(
|
||||||
|
address signer,
|
||||||
|
BN254.G1Point memory _signature,
|
||||||
|
uint votes
|
||||||
|
) external;
|
||||||
|
|
||||||
function makeEpoch() external;
|
function makeEpoch() external;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue