A Providence man will serve up to two decades in state prison after pleading guilty to raping a child in Attleboro.