Skip to content

Commit

Permalink
reversions
Browse files Browse the repository at this point in the history
  • Loading branch information
rauljordan committed Oct 24, 2023
1 parent 67ec1b3 commit 307e476
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 105 deletions.
49 changes: 15 additions & 34 deletions cmd/bold-deploy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func main() {
l2ChainConfig := flag.String("l2chainconfig", "l2_chain_config.json", "L2 chain config json file")
l2ChainName := flag.String("l2chainname", "", "L2 chain name (will be included in chain info output json file)")
l2ChainInfo := flag.String("l2chaininfo", "l2_chain_info.json", "L2 chain info output json file")
inputL2ChainInfo := flag.String("inputl2chaininfo", "", "The existing, deployed L2 chain info json file, if existent")
authorizevalidators := flag.Uint64("authorizevalidators", 0, "Number of validators to preemptively authorize")
txTimeout := flag.Duration("txtimeout", 10*time.Minute, "Timeout when waiting for a transaction to be included in a block")
prod := flag.Bool("prod", false, "Whether to configure the rollup for production or testing")
Expand Down Expand Up @@ -318,40 +317,22 @@ func main() {
panic(err)
}
parentChainIsArbitrum := l1Reader.IsParentChainArbitrum()
var chainsInfo []chaininfo.ChainInfo
if *inputL2ChainInfo == "" {
chainsInfo = []chaininfo.ChainInfo{
{
ChainName: *l2ChainName,
ParentChainId: l1ChainId.Uint64(),
ParentChainIsArbitrum: &parentChainIsArbitrum,
ChainConfig: &chainConfig,
RollupAddresses: &chaininfo.RollupAddresses{
Bridge: deployedAddresses.Bridge,
Inbox: deployedAddresses.Inbox,
SequencerInbox: deployedAddresses.SequencerInbox,
Rollup: deployedAddresses.Rollup,
ValidatorUtils: deployedAddresses.ValidatorUtils,
ValidatorWalletCreator: deployedAddresses.ValidatorWalletCreator,
DeployedAt: deployedAddresses.DeployedAt,
},
chainsInfo := []chaininfo.ChainInfo{
{
ChainName: *l2ChainName,
ParentChainId: l1ChainId.Uint64(),
ParentChainIsArbitrum: &parentChainIsArbitrum,
ChainConfig: &chainConfig,
RollupAddresses: &chaininfo.RollupAddresses{
Bridge: deployedAddresses.Bridge,
Inbox: deployedAddresses.Inbox,
SequencerInbox: deployedAddresses.SequencerInbox,
Rollup: deployedAddresses.Rollup,
ValidatorUtils: deployedAddresses.ValidatorUtils,
ValidatorWalletCreator: deployedAddresses.ValidatorWalletCreator,
DeployedAt: deployedAddresses.DeployedAt,
},
}
} else {
inputChainInfoFile, err := os.ReadFile(*inputL2ChainInfo)
if err != nil {
panic(fmt.Errorf("failed to read l2 chain config file: %w", err))
}
if err = json.Unmarshal(inputChainInfoFile, &chainsInfo); err != nil {
panic(fmt.Errorf("failed to deserialize chain info: %w", err))
}
// Edit everything but keep the same rollup contract as the original deployed info.
chainsInfo[0].RollupAddresses.Bridge = deployedAddresses.Bridge
chainsInfo[0].RollupAddresses.Inbox = deployedAddresses.Inbox
chainsInfo[0].RollupAddresses.SequencerInbox = deployedAddresses.SequencerInbox
chainsInfo[0].RollupAddresses.ValidatorUtils = deployedAddresses.ValidatorUtils
chainsInfo[0].RollupAddresses.ValidatorWalletCreator = deployedAddresses.ValidatorWalletCreator
chainsInfo[0].RollupAddresses.DeployedAt = deployedAddresses.DeployedAt
},
}
chainsInfoJson, err := json.Marshal(chainsInfo)
if err != nil {
Expand Down
38 changes: 4 additions & 34 deletions staker/state_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"strings"
"sync"
"time"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -44,35 +43,15 @@ var (
)

type BoldConfig struct {
Enable bool `koanf:"enable"`
Evil bool `koanf:"evil"`
Strategy string `koanf:"strategy"`
StakerInterval time.Duration `koanf:"staker-interval"`
MakeAssertionInterval time.Duration `koanf:"make-assertion-interval"`
PostingStrategy string `koanf:"posting-strategy"`
DisableChallenge bool `koanf:"disable-challenge"`
ConfirmationBlocks int64 `koanf:"confirmation-blocks"`
UseSmartContractWallet bool `koanf:"use-smart-contract-wallet"`
OnlyCreateWalletContract bool `koanf:"only-create-wallet-contract"`
StartValidationFromStaked bool `koanf:"start-validation-from-staked"`
ContractWalletAddress string `koanf:"contract-wallet-address"`
GasRefunderAddress string `koanf:"gas-refunder-address"`
RedisUrl string `koanf:"redis-url"`
ExtraGas uint64 `koanf:"extra-gas" reload:"hot"`
Enable bool `koanf:"enable"`
Evil bool `koanf:"evil"`
Mode string `koanf:"mode"`
}

func (c *BoldConfig) Validate() error {
return nil
}

type Opt func(*StateManager)

func DisableCache() Opt {
return func(sm *StateManager) {
sm.historyCache = nil
}
}

type StateManager struct {
validator *StatelessBlockValidator
historyCache challengecache.HistoryCommitmentCacher
Expand All @@ -86,7 +65,6 @@ func NewStateManager(
cacheBaseDir string,
challengeLeafHeights []l2stateprovider.Height,
validatorName string,
opts ...Opt,
) (*StateManager, error) {
historyCache := challengecache.New(cacheBaseDir)
sm := &StateManager{
Expand All @@ -95,9 +73,6 @@ func NewStateManager(
challengeLeafHeights: challengeLeafHeights,
validatorName: validatorName,
}
for _, o := range opts {
o(sm)
}
return sm, nil
}

Expand Down Expand Up @@ -360,12 +335,7 @@ func (s *StateManager) CollectMachineHashes(
if err != nil {
return nil, err
}
expectedEndingGlobalState, err := s.findGlobalStateFromMessageCountAndBatch(messageNum+1, cfg.FromBatch)
if err != nil {
return nil, err
}
expectedEnding := &expectedEndingGlobalState
stepLeaves := execRun.GetLeavesWithStepSize(uint64(cfg.MachineStartIndex), uint64(cfg.StepSize), cfg.NumDesiredHashes, expectedEnding)
stepLeaves := execRun.GetLeavesWithStepSize(uint64(cfg.MachineStartIndex), uint64(cfg.StepSize), cfg.NumDesiredHashes)
result, err := stepLeaves.Await(ctx)
if err != nil {
return nil, err
Expand Down
14 changes: 1 addition & 13 deletions system_tests/bold_challenge_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// For license information, see https://github.com/nitro/blob/master/LICENSE

// race detection makes things slow and miss timeouts
//go:build challengetest && !race

package arbtest

Expand Down Expand Up @@ -228,19 +229,6 @@ func TestBoldProtocol(t *testing.T) {
evilSeqInboxBinding, err := bridgegen.NewSequencerInbox(evilSeqInbox, l1client)
Require(t, err)

honestBatchCount, err := honestSeqInboxBinding.BatchCount(&bind.CallOpts{Context: ctx})
Require(t, err)
evilBatchCount, err := evilSeqInboxBinding.BatchCount(&bind.CallOpts{Context: ctx})
Require(t, err)

honestAcc, err := honestSeqInboxBinding.InboxAccs(&bind.CallOpts{Context: ctx}, big.NewInt(0))
Require(t, err)
evilAcc, err := evilSeqInboxBinding.InboxAccs(&bind.CallOpts{Context: ctx}, big.NewInt(0))
Require(t, err)

t.Logf("Honest inbox batch count %d, acc %x", honestBatchCount.Uint64(), honestAcc)
t.Logf("Evil inbox batch count %d, acc %x", evilBatchCount.Uint64(), evilAcc)

// Post batches to the honest and evil sequencer inbox that are internally equal.
// This means the honest and evil sequencer inboxes will agree with all messages in the batch.
totalMessagesPosted := int64(0)
Expand Down
4 changes: 1 addition & 3 deletions util/redisutil/redis_coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const INVALID_URL string = "<?INVALID-URL?>"

type RedisCoordinator struct {
Client redis.UniversalClient
url string
}

func WantsLockoutKeyFor(url string) string { return WANTS_LOCKOUT_KEY_PREFIX + url }
Expand All @@ -38,7 +37,6 @@ func NewRedisCoordinator(redisUrl string) (*RedisCoordinator, error) {

return &RedisCoordinator{
Client: redisClient,
url: redisUrl,
}, nil
}

Expand All @@ -62,7 +60,7 @@ func (c *RedisCoordinator) RecommendSequencerWantingLockout(ctx context.Context)
}
return url, nil
}
log.Error("no sequencer appears to want the lockout on redis", "priorities", prioritiesString, "redisUrl", c.url)
log.Error("no sequencer appears to want the lockout on redis", "priorities", prioritiesString)
return "", nil
}

Expand Down
2 changes: 1 addition & 1 deletion validator/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type ExecutionSpawner interface {

type ExecutionRun interface {
GetStepAt(uint64) containers.PromiseInterface[*MachineStepResult]
GetLeavesWithStepSize(machineStartIndex, stepSize, numDesiredLeaves uint64, expectedEndingGlobalState *GoGlobalState) containers.PromiseInterface[[]common.Hash]
GetLeavesWithStepSize(machineStartIndex, stepSize, numDesiredLeaves uint64) containers.PromiseInterface[[]common.Hash]
GetLastStep() containers.PromiseInterface[*MachineStepResult]
GetProofAt(uint64) containers.PromiseInterface[[]byte]
PrepareRange(uint64, uint64) containers.PromiseInterface[struct{}]
Expand Down
4 changes: 2 additions & 2 deletions validator/server_api/valiation_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ func (a *ExecServerAPI) GetStepAt(ctx context.Context, execid uint64, position u
return MachineStepResultToJson(res), nil
}

func (a *ExecServerAPI) GetLeavesWithStepSize(ctx context.Context, execid, fromStep, stepSize, numDesiredLeaves uint64, expectedEndingGlobalState *validator.GoGlobalState) ([]common.Hash, error) {
func (a *ExecServerAPI) GetLeavesWithStepSize(ctx context.Context, execid, fromStep, stepSize, numDesiredLeaves uint64) ([]common.Hash, error) {
run, err := a.getRun(execid)
if err != nil {
return nil, err
}
leavesInRange := run.GetLeavesWithStepSize(fromStep, stepSize, numDesiredLeaves, expectedEndingGlobalState)
leavesInRange := run.GetLeavesWithStepSize(fromStep, stepSize, numDesiredLeaves)
res, err := leavesInRange.Await(ctx)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions validator/server_api/validation_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ func (r *ExecutionClientRun) GetStepAt(pos uint64) containers.PromiseInterface[*
})
}

func (r *ExecutionClientRun) GetLeavesWithStepSize(machineStartIndex, stepSize, numDesiredLeaves uint64, expectedEndingGlobalState *validator.GoGlobalState) containers.PromiseInterface[[]common.Hash] {
func (r *ExecutionClientRun) GetLeavesWithStepSize(machineStartIndex, stepSize, numDesiredLeaves uint64) containers.PromiseInterface[[]common.Hash] {
return stopwaiter.LaunchPromiseThread[[]common.Hash](r, func(ctx context.Context) ([]common.Hash, error) {
var resJson []common.Hash
err := r.client.client.CallContext(ctx, &resJson, Namespace+"_getLeavesWithStepSize", r.id, machineStartIndex, stepSize, numDesiredLeaves, expectedEndingGlobalState)
err := r.client.client.CallContext(ctx, &resJson, Namespace+"_getLeavesWithStepSize", r.id, machineStartIndex, stepSize, numDesiredLeaves)
if err != nil {
return nil, err
}
Expand Down
17 changes: 1 addition & 16 deletions validator/server_arb/execution_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (e *executionRun) GetStepAt(position uint64) containers.PromiseInterface[*v
})
}

func (e *executionRun) GetLeavesWithStepSize(machineStartIndex, stepSize, numDesiredLeaves uint64, expectedEndingGlobalState *validator.GoGlobalState) containers.PromiseInterface[[]common.Hash] {
func (e *executionRun) GetLeavesWithStepSize(machineStartIndex, stepSize, numDesiredLeaves uint64) containers.PromiseInterface[[]common.Hash] {
return stopwaiter.LaunchPromiseThread[[]common.Hash](e, func(ctx context.Context) ([]common.Hash, error) {
machine, err := e.cache.GetMachineAt(ctx, machineStartIndex)
if err != nil {
Expand All @@ -67,15 +67,13 @@ func (e *executionRun) GetLeavesWithStepSize(machineStartIndex, stepSize, numDes
// to align with the state roots that the inbox machine will produce.
var stateRoots []common.Hash
startGlobalState := machine.GetGlobalState()
fmt.Println("==============")
if machineStartIndex == 0 {
hash := crypto.Keccak256Hash([]byte("Machine finished:"), startGlobalState.Hash().Bytes())
stateRoots = append(stateRoots, hash)
} else {
// Otherwise, we simply append the machine hash at the specified start index.
stateRoots = append(stateRoots, machine.Hash())
}
fmt.Printf("Initial global state: %+v, step size %d, start index %d, num desired %d, start hash %#x\n", startGlobalState, stepSize, machineStartIndex, numDesiredLeaves, stateRoots[0])

// If we only want 1 state root, we can return early.
if numDesiredLeaves == 1 {
Expand All @@ -95,7 +93,6 @@ func (e *executionRun) GetLeavesWithStepSize(machineStartIndex, stepSize, numDes
gs := machine.GetGlobalState()
hash := crypto.Keccak256Hash([]byte("Machine finished:"), gs.Hash().Bytes())
stateRoots = append(stateRoots, hash)
fmt.Printf("Finished state root idx %d, count %d pos %d, hash %#x, gs %+v\n", len(stateRoots)-1, machineStep, position, hash, gs)
break
}
// Otherwise, if the position and machine step mismatch and the machine is running, something went wrong.
Expand All @@ -104,22 +101,10 @@ func (e *executionRun) GetLeavesWithStepSize(machineStartIndex, stepSize, numDes
if machineRunning || machineStep > position {
return nil, fmt.Errorf("machine is in wrong position want: %d, got: %d", position, machineStep)
}
fmt.Println("Machine status", machine.Status())
}
gs := machine.GetGlobalState()
hash := machine.Hash()
stateRoots = append(stateRoots, hash)
fmt.Printf("State root idx %d, count %d pos %d, hash %#x, gs %+v\n", len(stateRoots)-1, machineStep, position, hash, gs)
}

// if expectedEndingGlobalState != nil {
// hash := crypto.Keccak256Hash([]byte("Machine finished:"), expectedEndingGlobalState.Hash().Bytes())
// fmt.Printf("Replacing %#x with %#x from %+v\n", stateRoots[len(stateRoots)-1], hash, expectedEndingGlobalState)
// stateRoots[len(stateRoots)-1] = hash
// } else {
// fmt.Println("Final modify disabled")
// }

// If the machine finished in less than the number of hashes we anticipate, we pad
// to the expected value by repeating the last machine hash until the state roots are the correct
// length.
Expand Down

0 comments on commit 307e476

Please sign in to comment.