aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs47
1 files changed, 36 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs
index 880d793..7c819e5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -165,18 +165,37 @@ async fn main() -> Result<()> {
&files,
&force,
)?;
- let (initial_doc, starting_epoch, starting_swarm, earlier_actors, initial_signatures) =
- match starting {
- Some(starting) => (
- starting.doc,
- Some(starting.epoch),
- Some((starting.swarm_id, starting.origin)),
- starting.earlier_actors,
- starting.signatures,
- ),
- None => (Document::new(), None, None, Vec::new(), Vec::new()),
- };
+ let (
+ initial_doc,
+ starting_epoch,
+ starting_swarm,
+ earlier_actors,
+ initial_signatures,
+ resumable,
+ ) = match starting {
+ Some(starting) => (
+ starting.doc,
+ Some(starting.epoch),
+ Some((starting.swarm_id, starting.origin)),
+ starting.earlier_actors,
+ starting.signatures,
+ starting.resumable,
+ ),
+ None => (Document::new(), None, None, Vec::new(), Vec::new(), None),
+ };
let mut initial_doc = initial_doc;
+ // Writing on as the actor of before, where this node stopped cleanly: everything it
+ // wrote as that one is in the document, so no change of it comes twice.
+ match resumable.filter(|_| args.keep_actor) {
+ Some(actor) => {
+ info!(actor = %actor, "Writing on as the actor of before (--keep-actor)");
+ initial_doc.set_actor(actor);
+ }
+ None if args.keep_actor && starting_epoch.is_some() => {
+ info!("Writing as a fresh actor: this node didn't stop cleanly (--keep-actor)");
+ }
+ None => {}
+ }
if let Some(spec) = &args.remake {
remake::remake_genesis(spec, &files, &mut initial_doc)
.with_context(|| format!("Making the genesis document (--remake {spec})"))?;
@@ -228,6 +247,11 @@ async fn main() -> Result<()> {
args.document_rewrite,
))
});
+ // A clean stop's mark undone before anything is written: a crash from here on
+ // leaves a file that doesn't say so.
+ if let Some(file) = &document_file {
+ file.open();
+ }
let node = node::Node::new(node::NodeConfig {
transport,
identity: Some(transport::identity::IdentityConfig {
@@ -367,6 +391,7 @@ async fn main() -> Result<()> {
swarm::peer::farewell(&state).await;
swarm::state_file::update(&state, true).await;
swarm::document_file::flush(&state).await;
+ swarm::document_file::close(&state).await;
Ok(())
}